Flutter Provider V3 Architecture | ProxyProvider for Dependency Injection

Поділитися
Вставка
  • Опубліковано 10 лип 2024
  • In this Flutter Provider tutorial we use the ProxyProvider to setup dependency injection and build a complete production ready architecture for an app.
    Written:www.filledstacks.com/post/flu...
    Starting Code: firebasestorage.googleapis.co...
  • Наука та технологія

КОМЕНТАРІ • 148

  • @FilledStacks
    @FilledStacks  5 років тому +6

    If you run the app before we fix the _busy value. Set the _busy default value to false in the LoginModel. bool _busy = false

  • @ht98888
    @ht98888 3 роки тому

    Excellent tutorial. Fast, to the point, and accurately states and assumes prior knowledge. Big fan.

    • @FilledStacks
      @FilledStacks  3 роки тому

      Thanks for the awesome feedback! I really appreciate it. And thanks for watching :)

  • @jhvkgvb
    @jhvkgvb 5 років тому +1

    Whelp! Time to change the architecture of all my applications to this one haha! Great vid as always! :)

    • @FilledStacks
      @FilledStacks  5 років тому

      haha 🤣 It's a great architecture. Easy to manage. Goodluck with that refactor 😉

    • @FilledStacks
      @FilledStacks  5 років тому +3

      Just so you know i still use my architecture that depends on get_it for dependency injection. I don't like the provider only approach at the moment.

    • @jhvkgvb
      @jhvkgvb 5 років тому

      Oh, interesting. Care to elaborate why? ☺️

    • @FilledStacks
      @FilledStacks  5 років тому +9

      @@jhvkgvb Sure.
      It's easier to maintain: Using provider only the dependency injection code has multiple areas of change when you introduce a new dependency. The locator file, then you have to make sure the services required by the new provider is above it. Then write the code to inject the dependencies of that service. When that's complete you have to update the injection code into the ViewModel where it's required.
      With get it you just add the new service to the locator and then request it in the model it's required.
      The above point also covers, less boiler plate. Less specific code related to dependency injection and almost the most important, it's easier to read, and easier to understand (for that is).
      I've mentioned before but I don't like to write more code to get the same functionality that less code can give me, and in this case the code also looks better. I also don't write code I don't like because it's "Pure" or doesn't go against the frame work patterns. So provider (as a dependency injection tool) has a long way to go for me before I'll decide to use it over get_it. That involves mostly around the verbosity. Which is hard thing to combat in Flutter.

  • @martinharris4416
    @martinharris4416 4 роки тому +2

    No one :
    FilledStacks : *Lets create a new file*

    • @FilledStacks
      @FilledStacks  4 роки тому

      hehe, can't have all the code in 1 file

  • @ahmetkocadogan1890
    @ahmetkocadogan1890 5 років тому +1

    My stacks are filled , thanks :)

    • @FilledStacks
      @FilledStacks  5 років тому +1

      Yeeeaaaah, there we go. That's the goal for all of us :)

  • @dellaian
    @dellaian 5 років тому

    Great architecture, really well done

    • @FilledStacks
      @FilledStacks  5 років тому

      Thank you, very much appreciated.

  • @SilasSWF
    @SilasSWF 5 років тому

    Excelente tutorial!

  • @gmc254quads6
    @gmc254quads6 5 років тому

    @FilledStacks And just like that, you may have potentially killed 'get_it' for me. This is a very nice tutorial, and the written tutorial is even better. Looks like it's time I changed even my architecture. I like the way you broke down provider in a way that I finally like it.

    • @FilledStacks
      @FilledStacks  5 років тому +1

      Niiice!! Yeah it's definitely not as bad as I thought it was going to be. I still prefer get_it for the larger projects where the model dependencies are always changing as I expand. It would be little bit of a pain to keep on updating the provider signatures as I remove / add dependencies from the models and the services. But I have seen some community members change to this one and they're loving it 👌 plus having only one package that does dependency "providing" in there is a massive win.

  • @quang.luu.179
    @quang.luu.179 5 років тому

    Awesome vid @FilledStacks , is there any video for BLOC ?

    • @FilledStacks
      @FilledStacks  5 років тому +3

      Thanks man! There are no videos for bloc from me, or that I plan on doing for Bloc. I couldn't figure out the architecture separation myself. If a bloc manages the state of a widget, or a feature. And there's no clear guidelines so I didn't want to spend time learning something like that if I could use provider and use my own approach to simplify statemanagement in my apps.

  • @martinrupertbulquerin228
    @martinrupertbulquerin228 5 років тому +1

    Hi @FilledStacks, Thank you for this tutorial. May I know how you can pass data using your RoutePaths?

    • @FilledStacks
      @FilledStacks  5 років тому

      RoutPaths just stores the name of the paths to navigate to. In your navigation call you just put the argument and then extract it in the Router. There's an example in the current Router, look at the Post case.

  • @edwardamewu
    @edwardamewu 4 роки тому

    this is amazing... thanks for this ... you deserve two likes from me ❤❤❤❤

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      Thank you :) I will accept those two likes :)

    • @edwardamewu
      @edwardamewu 4 роки тому +1

      @@FilledStacks
      Hi and Thank you for the amazing work you are doing 👍👍.
      Okay so i have used this awesome solution you have provided in a project am working on.
      I am three weeks old to this framework and am loving it.
      Anyways i need help with an issue I am facing with refreshing data of previous page on navigation.pop().
      I wanted to know how best to handle this... before hacking my way through thank you in advance. 😊😊😊

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      @@edwardamewu AWESOME! You await your initial navigation call and then you return a value in the pop function to indicate to yourself that you want to refresh the data.

    • @edwardamewu
      @edwardamewu 4 роки тому

      @@FilledStacks Wow that was quick... thanks

  • @sheltiesu0827
    @sheltiesu0827 5 років тому +2

    Thank you for all the flutter videos. Do you have a plan to make a course or show us how make a large application with this architecture?

    • @FilledStacks
      @FilledStacks  5 років тому +4

      I am planning to do something like that, i was hoping this video would be enough to give you the idea of how to build this. But i can definitely do a course on it as well. It's not going to be anytime soon because of client work. But I'll start thinking about it more seriously.

  • @kobowo
    @kobowo 4 роки тому +2

    Nice tutorial, I kinda get how to use Provider now (I mean in a meaningful way). Minor comment: I think you talk too fast at some times but still, amazing tutorial. Thanks!

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      Thanks 😊 I have received that comment before. I slow it down in the later videos. I think 😅

  • @hanielbaez5723
    @hanielbaez5723 5 років тому

    Hi @FilledStacks, when you are settingup the "Provider", what is the "..." for. I mean "...independentServices,
    ...dependentServices".

    • @FilledStacks
      @FilledStacks  5 років тому +1

      It's like the spread operator in java scrip. It adds all the items from the list after ... into the current list. So there it's adding all the independentServices list items and the dependentServices list items into the new list.

  • @sreekumarmenon
    @sreekumarmenon 5 років тому +2

    FilledStacks , awesome videos, waiting for video on video on flutter + graphql , thank you

    • @FilledStacks
      @FilledStacks  5 років тому +1

      GraphQL is mostly server side setup but I can probably go over how to construct the query on the device. It'll be some basic json building in dart. I think there's a few packages that do it, maybe one day I'll make a video on it.

    • @sreekumarmenon
      @sreekumarmenon 5 років тому

      @@FilledStacks more interested in seeing how it works with your recommended architecture. thanks

    • @FilledStacks
      @FilledStacks  5 років тому +3

      @@sreekumarmenon Aaah. Well I can tell you now I'll create a service called api, which will use my QueryBuilder class to build the query and make the http request. Then I'll use that api in the model 😁 the answer is always the same with this architecture. Make a service that wraps your functionality. Use that service in your model if you require the functionality. Anything specific about the architecture that you think would be different when using graphQL compared to any other service in the app like a localStorage service?

  • @iCreeative
    @iCreeative 5 років тому +1

    Great video, thanks for sharing!
    Do you have in plan made Flutter Provider v4 :D , and what do you think about keeping models and view together in one directory, I mean separate more by feature (Post, Comment, etc.) than type of file (model, view etc.)?

    • @FilledStacks
      @FilledStacks  5 років тому +2

      Haha, if Provider releases v4 and the new introductions provides a new way to architect the app then I'll make one 😁
      And with your file structure. That's perfectly fine as well. That will work out well if you have many distinct features or groups in your app. The directory structure could be however you want it, the internal workings of the architecture is what I was trying to show.
      Thanks for watching and the comment.

    • @talatkuyuk6556
      @talatkuyuk6556 4 роки тому

      @@FilledStacks Hi, I am fan of you, Provider has released the v4 and it has changed with something as you know. Do you plan to produce a new tutorial for the same project as you promised:) ?

    • @FilledStacks
      @FilledStacks  4 роки тому

      @@talatkuyuk6556 Hi, thanks. I haven't seen much changes besides a rename of the builder function to create so I won't be making a new video. I still use exactly the same architecture as the video before this using get_it + provider.

  • @MohammedNoureldin
    @MohammedNoureldin 3 роки тому +1

    Thank you for this nice explanation. I got some cool ideas from it. Nevertheless, I would not use this approach in a production app as it over-complicates the problem, imo.

    • @FilledStacks
      @FilledStacks  3 роки тому

      You're welcome, I'm happy it helps. We also don't use this in production. This was to teach how to use Provider only for State management and dependency injection which I don't think is a good idea. We use Stacked and get_it for that in production which makes everything way simpler.

  • @mattrisby696
    @mattrisby696 5 років тому

    Great video. I do have a couple of questions though. If I wanted to create a simple state for say application preferences, would this be created in the viewmodel and inherit the base_model? Also, how would I then implement this within provider_setup? Many thanks.

    • @FilledStacks
      @FilledStacks  5 років тому

      Yes, I do it in this video ( youtu.be/kDEflMYTF ). I create a simple state with the enum and put it in the base view so all models can inherit it. You don't have to implement it differently based on provider. You still implement a base class and your other models inherit that, nothing special about the code that has to be written for provider.

    • @mattrisby696
      @mattrisby696 5 років тому

      @@FilledStacks Of course, I think I was making it more complicated than it needed to be. Thanks.

  • @EmreAltunbilek
    @EmreAltunbilek 5 років тому

    Hello, thanks for videos, they are great.. i have a problem with provider package and i hope you can help me...
    i am fetching data from api about weather and when i get the data i wanna change all theme of my app by using fetched weather data from api.. i mean if it is clean weather, i want to make yellow theme etc..
    I made 2 viewmodel file, one of about weather, other one is about theme..
    my code is like:
    Get Weather, when fetch the data call method on ThemeViewModel to change the entire theme..
    I have a error at this point it says:
    The following assertion was thrown while dispatching notifications for MyThemeViewModel:
    I/flutter ( 2686): setState() or markNeedsBuild() called during build.
    I/flutter ( 2686): This ChangeNotifierProvider widget cannot be marked as needing to build because
    I/flutter ( 2686): the framework is already in the process of building widgets. A widget can be marked as needing to be
    I/flutter ( 2686): built during the build phase only if one of its ancestors is currently building. This exception is
    I/flutter ( 2686): allowed because the framework builds parent widgets before children, which means a dirty descendant
    I/flutter ( 2686): will always be built. Otherwise, the framework might not visit this widget during this build phase.
    I/flutter ( 2686): The widget on which setState() or markNeedsBuild() was called was:
    I/flutter ( 2686): ChangeNotifierProvider(state: _DelegateWidgetState#8faf0)
    I/flutter ( 2686): The widget which was currently being built when the offending call was made was:
    I/flutter ( 2686): WeatherApp(dirty, dependencies: [InheritedProvider,
    I/flutter ( 2686): InheritedProvider])

    • @FilledStacks
      @FilledStacks  5 років тому

      Hi, that stack trace and logs won't help me. I would suggest setting up your theme manager like this (www.filledstacks.com/snippet/build-a-theme-manager-in-flutter), defining your theme as one of the themes in the list and then updating it when your data comes back. You don't need a view model to manage your themes view models are for views/widgets with logic.

  • @SreekumarMenonPhotography
    @SreekumarMenonPhotography 5 років тому

    @filedStacks , I had to read the article few times to understand the proxyprovider , thanks for the article. One thing that is still confusing to me is Consumer has child and builder - and in loginview, you are passing loginheader into child and builder with button into builder, could you explain the difference ?

    • @FilledStacks
      @FilledStacks  5 років тому

      Hey, thanks for checking it out. The child property is a widget that only needs to be built once, meaning it's UI won't change depending on any value in the model. The login header never has to change so we can pass it in as a static child and display it in the builder. It's only ever "built once". When you use the builder "everything" in your builder function is rebuilt whenever change notifier is called.

    • @SreekumarMenonPhotography
      @SreekumarMenonPhotography 5 років тому

      @@FilledStacks Got it! Thanks for the response. In login view .i see that you are placing child inside column as first child ,followed by other widgets (button). This is easy for a simple UI like login, for a complex UI that has more widgets ,how does this work? example if there is loginheader and then button and then below that loginfooter ,both login header and footer does not change? can we have more than one child but used in different places?

  • @yuniwidiasmara5413
    @yuniwidiasmara5413 5 років тому +1

    Hey FilledStacks thanks for your sharing this tutorial, i still confuse how to design & animate in flare, can you make the tutorial?

    • @FilledStacks
      @FilledStacks  5 років тому

      I have one where we animate a slide out menu. You can watch that one to get an idea. My new video is about Flare as well.

  • @kami2144
    @kami2144 5 років тому +1

    Hi @FilledStacks, Thanks for sharing this tutorial! Would you be expanding this video out for handling no network connection when it is loading and also search delegate? I would love to see that!

    • @FilledStacks
      @FilledStacks  5 років тому +1

      Hi there. I will not be doing this at that point, I won't be covering specific situations that's application specific for now. I'd like to cover broader more architectural concepts like the new video where you use managers to interact with your UI from the models. network connectivity handling can be built into the architecture in a way so I definitely will cover that in the future but not search delegate. That's an implementation detail specific some apps only.

  • @Yasser3664
    @Yasser3664 5 років тому +1

    So for the version 3 the code feeled like more the GetIt now ? that's how I see it, correct if I'm wrong.
    Also I think the multiprovider is easier than the method you use it in the provider architecture without GetIt the first time, I think it's in the lesson 10 repo that folder without get it named, no ?
    And finally can you tell me what will you use on your next projects the multiProvider or GetIt (Which is better based on your opinion and experience) ?

    • @FilledStacks
      @FilledStacks  5 років тому +2

      Hi Yasser. The title and thumbnail is a bit confusing here, it's actually architecture using Provider V3. The only difference is that we're not using get_it. I wanted to make a video to show that so that people had the option. I still use the architecture I first laid out that uses get_it. I'm more comfortable when it comes to the maintenance of the code so I'll stick to that for now.

    • @rydmike
      @rydmike 5 років тому

      @@FilledStacks I was going to ask you which version you were using yourself. I liked to get_it version a bit better too, but this is certainly an option now as well with the new version of Provider.

    • @FilledStacks
      @FilledStacks  5 років тому

      @@rydmike Yeah, this is definitely an option as well now. I don't know when I'll use it, but it's an option. Since get_it is so quick to setup I always opt for that.

  • @WCKD_OFFICIAL
    @WCKD_OFFICIAL 4 роки тому

    Hello, mate!
    Provider V4 is out. Are you considering making a new arhitecture video on it? If yes, I would like suggesting including also the abtractisation tehniques into the tutorial so users will have a complete perspective on how to design the core of their apps.
    Thanks!

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      heloooo, I'll see what differences it has introduced and see if the architecture will change much given new functionality. On the abstraction, I'd probably use it in the tutorial but I won't make a video that goes over it again. There's lots of times where I don't use abstraction to reduce overhead.

    • @WCKD_OFFICIAL
      @WCKD_OFFICIAL 4 роки тому

      FilledStacks Thanks for your reply, mate. I really appreciate. Following your previous V3 comparing it to the new version there seems to be some updates regarding the argument names and some new rules on how to create and access instances. Regarding the abstraction, I would love to see how you link it together with the tutorial, without having to say over and over on how abstraction works and what benefits it comes with. Just pure integration of it with the provider V4 tutorial. Thanks a ton!

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      @@WCKD_OFFICIAL I see. i have seen those parameter name updates. I do the integratation in my abstraction video. I'll only be doing that maybe a few months from now if I even do it. I have a firebase series planned next for the start of next year.

    • @WCKD_OFFICIAL
      @WCKD_OFFICIAL 4 роки тому

      FilledStacks Thanks, it would be nice to make a series of how to build a social media app clone with firebase. I have seen some on UA-cam but they follow no guidelines unfortunately . 😔 Happy holidays and a happy new year!

  • @tuananhphan3159
    @tuananhphan3159 3 роки тому

    Thanks for nice video. I got this issue while follow your architecture "Unhandled Exception: Error: Could not find the correct Provider above this LoginView Widget
    ". I follow your tutorial step by step so cannot understand why my code show this issue. Can you help me? Many thanks

    • @FilledStacks
      @FilledStacks  3 роки тому

      Thanks. You're not providing the LoginViewModel above the context where you're wanting to access it.

  • @g-luu
    @g-luu 4 роки тому

    Great content as always. I am coming from a redux world so I am still investigating which architecture is best for flutter apps. I do not mind the boilerplate cause it makes sense why they have it. Jut concerned more about rebuilds between these architectures.

    • @FilledStacks
      @FilledStacks  4 роки тому +2

      Thank you. I also like redux. You could still use it here as well and use provider for your Viewmodel rebuilds after modifying your states. I'll be sharing a revised version of my Mvvm architecture and soon when I've done all the change / update reviews on it.

    • @g-luu
      @g-luu 4 роки тому

      @@FilledStacks Thanks looking forward to that.

  • @massaybah4758
    @massaybah4758 4 роки тому

    Provider.of(context).email always returns null after migrating to Provider v4.
    Since there were some syntax changes in the new version, I changed the below consumableProviders:
    List uiConsumableProviders = [
    StreamProvider(
    create: (context) => Provider.of(context, listen: false).user
    )
    ];
    Please help out! Thanks

    • @FilledStacks
      @FilledStacks  4 роки тому

      That looks fine to me. Ensure that the user isn't broadcast before you subscribe.

  • @khalilamor7771
    @khalilamor7771 5 років тому +2

    Can you please explain in like 2 or 3 phrases the purpose of all this?
    I am new to flutter and I recently just learned how to use the Bloc pattern (So I am somehow an expert beginner :p ).
    So is this ProxyProvider a better alternative for Bloc or is it an architecture that is scalable and maintainable or is the main goal of all this is code reusability?
    Thank you very much for sharing all this knowledge

    • @karlon908
      @karlon908 5 років тому

      Khalil amor Provider is another state management pattern for flutter, it is an alternative for bloc pattern.
      The video above explains about the use of the new feature from provider library which is the dependency injection without context. Similar to get_it library.
      Provider is like bloc pattern but simpler.

    • @ZolzayaErdenebaatar
      @ZolzayaErdenebaatar 5 років тому +1

      I build an app with Bloc. But it's very heavy and hard. Provider is easy to understand and easy to implement it. From the 3.0 version it's getting powerful.

    • @FilledStacks
      @FilledStacks  5 років тому +3

      Hi Khalil, the purpose of having an architecture in place is simply to make development of your app easier in the long run. Provider is a state management library and a dependency injection library in one. You can use provider just for dependency injection and provide your Bloc's where they are required, you don't have to use one or the other. This video is an architecture for if you want to use Provider only. For state management and dependency injection.
      ProxyProvider is not an alternative to Bloc. It's an alternative to get_it. Block is for state management, not dependency injection. I have a video describing a beginner level version of Dependency Injection as well, you should watch that if you don't know what it is.

    • @khalilamor7771
      @khalilamor7771 5 років тому

      @@FilledStacks Thank you very much for the explanation :D so much appreciated

  • @phyo936
    @phyo936 4 роки тому

    Can you provide another tutorial with provider 4.0.5 and the tutorial inside is only with version 3. Will it change lot after upgrade.

    • @FilledStacks
      @FilledStacks  4 роки тому

      Nothing changed for me. The only difference was using create instead of builder

  • @davidurbina6555
    @davidurbina6555 5 років тому

    Would be great to see a Google map implementation using this architecture.

    • @FilledStacks
      @FilledStacks  5 років тому

      I wouldn't do anything other than adding the google map widget and using the callbacks to direct to my model to do all the work. Once you really understand the architecture and how to break down the problems into single responsibility problems then everything in development within the flutter apps become much easier.

  • @mfccreations9632
    @mfccreations9632 4 роки тому

    I have the error Scaffold' is not a subtype of type '(BuildContext, ChangeNotifier, Widget) => Widget'

    • @FilledStacks
      @FilledStacks  4 роки тому

      Make sure you provide your generic type everywhere you use the function as well as with your viewmodel

  • @lasitha6251
    @lasitha6251 4 роки тому

    pub.dev/packages/provider clearly says don't use Provider.value to create your object, which you showed in here like Provider.value(value: Api()). What was that about they were saying?

    • @FilledStacks
      @FilledStacks  4 роки тому

      The video is almost 1 full year old :) Remi miiiiiight just have updated the readme and package from then till now. The video makes use of provider v3, v4 is already out.

    • @lasitha6251
      @lasitha6251 4 роки тому

      @@FilledStacks got it

  • @julianarnold7992
    @julianarnold7992 5 років тому

    Which icons extension are you using for the solution explorer?

    • @FilledStacks
      @FilledStacks  5 років тому +1

      It's called VSCode Great Icons

  • @wilfred5656
    @wilfred5656 3 роки тому

    You too much. Greetings from portharcourt, nigeria.

    • @FilledStacks
      @FilledStacks  3 роки тому

      :D greetings! And thanks for watching

  • @peace2941
    @peace2941 4 роки тому

    I found some people, calling the change notifier provider directly form the mutliprovider list, does that affect the app performance ?
    void main() => runApp(
    MultiProvider(
    providers: [
    ChangeNotifierProvider(
    builder: (_) => MyClass(),
    ),

    ],
    child: App(),
    ),
    );
    How can I test how bad is this to a medium Application?
    Thanks in advance.

    • @FilledStacks
      @FilledStacks  4 роки тому

      No it doesn't. If your app is lagging you should optimise for performance. It's hard to solve a problem that you don't even know if it exists.

    • @peace2941
      @peace2941 4 роки тому

      @@FilledStacks Thank you so much for answering my question! I'll give it a try and test it out then.

  • @dhiliph534
    @dhiliph534 4 роки тому +1

    Hey FilledStacks, best architecture video in UA-cam. Thanks a lot. I like the idea of having a view model for each view for handling the state of the view, but I wonder how the data is being shared between two views.. For example, let's assume we have three screens. A Menu Screen where all the items are displayed with a Add to Cart Button. One Home Screen which consist of few recommended/suggested items to the user and also Cart button with the details of how many items are in the cart. I also have a cart page. Now irrespective of the page in which the user adds items to the cart, all my screens should share the common data. How do I implement this with the Provider pattern. Because I don't have any central store from which all the three widgets can fetch the data.

    • @FilledStacks
      @FilledStacks  4 роки тому

      Thanks Dhilip I appreciate the feedback :) Based on your question I assume you haven't watched my part two of the architecture using provider and get_it. It's the architecture video before this one. The viewmodels just manage the state of the view, they also make use of services that can be injected to perform functionality, that are always singleton so they can have shared data. In your case I will have a CartService that can be injected everywhere, updated and then the information read in the other models as well. BAsically your app will consist of Views, ViewModels, Services and Managers to interact with UI specific code through services. I have videos of all of it on my channel :)

    • @dhiliph98
      @dhiliph98 4 роки тому

      @@FilledStacks I somehow missed the second part of the architecture tutorial. It answered all my questions. Thanks a lot man!! :)

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      @@dhiliph98 haha, most people do :) You're welcome.

  • @HappySoundsOfficial
    @HappySoundsOfficial 5 років тому

    How can you create a StreamProvider, which depends on a Future value?

    • @FilledStacks
      @FilledStacks  5 років тому

      I have never thought of that because I wouldn't return a Stream from a future. I don't see any situation where you'd want to do that. Why not run the Future on it's own and emit values over the stream and just return the stream for the app to consume?

    • @HappySoundsOfficial
      @HappySoundsOfficial 5 років тому

      @@FilledStacks Well in my situation I am using firebase for user auth and database. And I want to add a StreamProvider of a User object stream from the database to the whole app, but in order to get the reference to the stream, I need the user id, which is only accessible from firebaseauth.currentUser which is a future.

    • @FilledStacks
      @FilledStacks  5 років тому +2

      @@HappySoundsOfficial Yeah, I've done that before. You can just run your Future, get the value off and put it onto a UserStream. similar to what's done in the AuthenticationService of this Architecture video. In your AuthenticationService you subscribe to the user, get the current user using the .then call, when it comes back you add it onto your controller. That's the controller your expose through provider, you don't need to introduce the Future in there as well. The service can take care of getting your user and putting it on the stream.
      Watch my "building a feedback app" video to see how I expose only streams and just emit values from within the service.

    • @HappySoundsOfficial
      @HappySoundsOfficial 5 років тому

      @@FilledStacks Thanks!

  • @nishantdesai3705
    @nishantdesai3705 5 років тому

    at 15:50, we will never get new instance of AuthenticationService, right?

    • @FilledStacks
      @FilledStacks  5 років тому

      No we won't. We set listen to false for that reason.

    • @nishantdesai3705
      @nishantdesai3705 5 років тому

      @@FilledStacks Can you explain how, so my reasoning is that we have registered one instance of type Authentication Service using ProxyProvider which depends on instance of APIService which we have also registered via Provider.value and we are accessing AuthenticationService and API via Provider.of so how will we get an instance of API service of AuthenticationService different from our registered instances ?

    • @FilledStacks
      @FilledStacks  5 років тому

      You'll still get a different instance in this case, the only thing that won't happen is the StreamProvider won't rebuild itself when the AuthenticationService gets a new value or new instance. Are you asking how to implement singleton services in Provider because I don't know what you're asking.

    • @nishantdesai3705
      @nishantdesai3705 5 років тому

      @@FilledStacks the thing that I'm asking is that how do we get new instance of Api and Authentication services because we have registered one instance of both of these services (using Provider.value and ProxyProvder) and if we are accessing them via Provider.of how are we going to get new instances of those services.
      I thought that you are implemented Singleton pattern, am i making a mistake here?

    • @FilledStacks
      @FilledStacks  5 років тому

      @@nishantdesai3705 No you're right. I'm using the "singleton" pattern. If you want a new instance of them then you won't register them through the provider, instead you can just create new instances of it as we do with the Models for the view. You can make helper functions to do inject construction and injection using reducers to make it easier to ready, but if you want a new instance you'll have to construct one.

  • @yuwenpixon
    @yuwenpixon 4 роки тому

    How do you put a pull to refresh feature using this pattern?

    • @FilledStacks
      @FilledStacks  4 роки тому

      This pattern wouldn't affect any UI implementations. So the same as you would in a normal flutter app. The only difference would be that when it's triggered you call a method on your viewmodel and don't run the refresh code directly in the UI.

    • @yuwenpixon
      @yuwenpixon 4 роки тому

      Ok, I got i! very awesome tutorial! Less boilerplate code using this pattern. Thanks to you man. :)

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      @@yuwenpixon Thanks man, appreciate the kind words. I'm happy to hear it's improving your code.

  • @Mohamedhassan-if8ww
    @Mohamedhassan-if8ww 5 років тому

    Thank you Again for clarifying things but can i ask you something about notifylistners(); . if i call it does it rebuild all the consumers or the baseview in our case . or it build only the consumer who use the object where we called notifylisteners .And to be honest i will stick with the get it approach no boiler plate and easy to implement and update ,with the proxy provider one change can be hard as the app grows . Thank you for ur time . i should buy you more coffee

    • @FilledStacks
      @FilledStacks  5 років тому +1

      It rebuilds only the consumer that the object belongs to so in. So when we call notify listeners when the comments model change, that's the only UI that gets rebuilt. The post view itself will not be rebuilt again. That's the reason you want to keep your models small and your UI well separated as well, not only will you gain ease of maintenance with the smaller code files and separated logic. You'll also gain performance benefits on larger views because the overall UI is built less as we only rebuild the small pieces of UI that the model is associated with.
      And I agree with you. I'm still using get_it as well. It's much cleaner, and I've also tried to use provider only with the apps I have and everytime I either combine services or split them apart it's a dependency (in source code) nightmare having to go through and update them, re-arranging services to make sure they are provided in the correct order etc. I might switch to not registering models in the locator. I quite like that, and I'll just construct them as they are required. This will give me the option of passing additional parameters as well incase I want to decouple some more things and make the model a bit more testable.

    • @Mohamedhassan-if8ww
      @Mohamedhassan-if8ww 5 років тому

      @@FilledStacks True . I hope you can keep us Updated when u decide to change anything within the locator or How to Structure The project . I Wwant to ask you something about The notifylistners() again . In ur V2 Video you changed the like Functionality in like_button_model.dart but i still cant get how the likes in the post get rebuilded when only the consummer of like button should update .

    • @FilledStacks
      @FilledStacks  5 років тому +1

      I like count in the Post view is up to date because when you get back to the Posts view Flutter calls the build function again to rebuild the widget. At that point it gets the posts from the postsService which has now been updated by the like button so when the rebuild happens it now has the updated value from the posts service.

    • @Mohamedhassan-if8ww
      @Mohamedhassan-if8ww 5 років тому

      @@FilledStacks Still not clear . When we call the methode increaseLikes() and as you say it should rebuild only the consumer that uses LikeButtonModel But It manage to rebuild the postview Wish have no relation with the build methode of LikeButtonModel . Soory But i think i missing something or i am getting something wrong

    • @FilledStacks
      @FilledStacks  5 років тому

      @@Mohamedhassan-if8ww Yes you are getting something wrong. The Post view is not being rebuilt. An easy way to test that is to put a break point in the builder and see if it gets hit when you click on the like button. As you'll see it won't get there because nothing in the PostViewModel is calling notify Listeners. The Posts view isn't updated because it's rebuild through the builder in the base view. It's updated because when it gets back to the view Flutter runs the entire build function again and because it's a stateless widget it pulls all new data from the model. When the model indexes into the PostService to get the new list of data, the data that has been updated by the like button model, then it shows the latest like button. It's pulling from a singleton source. You might be confused with the builder being called based on notifyListeners and the *build method* being re-run by Flutter to redraw the UI. This happens on many occasions, when you navigate to a view, when you navigate back, when you show a dialog, when you open the keyboard, when you lock the device, when you minimise the app etc.

  • @bibash3128
    @bibash3128 5 років тому

    If I want each dart file for each api.. how will I handle this?

    • @FilledStacks
      @FilledStacks  5 років тому

      You create a file for each api endpoint if that's what you're asking.

    • @bibash3128
      @bibash3128 5 років тому

      @@FilledStacks yes... Do I have to do any extra work?

  • @bibash3128
    @bibash3128 5 років тому

    When can we expect like implementation in v3?

    • @FilledStacks
      @FilledStacks  5 років тому

      This video is the implementation for Provider V3

    • @bibash3128
      @bibash3128 5 років тому

      @@FilledStacks I meant to say like counter

  • @martinharris4416
    @martinharris4416 4 роки тому +1

    GET_IT IS SOO MUCH BETTER
    - A BEGINNER

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      haha, it does help quite a lot with the readability of the code, and the setup, and the usage.

  • @pradeep422
    @pradeep422 5 років тому

    why extends instead with keyword?????? with changenotifier......

    • @FilledStacks
      @FilledStacks  5 років тому +1

      I don't know what you're saying or asking if that's a question.

    • @pradeep422
      @pradeep422 5 років тому

      In the example included in provider package, WITH keyword used while ur using EXTEND with ChangeNotifier( for example in viewmodel class).. Im just curious why????

    • @FilledStacks
      @FilledStacks  5 років тому +2

      ChangeNotifier is not a mixin so I don't see a reason to use with. I'm extending the class making it a subclass of changenotifier. I don't know why Remi used with instead of extends. But i only use with when using mixins.

    • @talatkuyuk6556
      @talatkuyuk6556 4 роки тому

      @@FilledStacks Here is a good explenation that I have found: stackoverflow.com/questions/56680226/should-you-use-extends-or-with-keyword-for-changenotifier-flutter

    • @talatkuyuk6556
      @talatkuyuk6556 4 роки тому

      stackoverflow.com/questions/56680226/should-you-use-extends-or-with-keyword-for-changenotifier-flutter

  • @raykoster3562
    @raykoster3562 4 роки тому

    if anyone has a idea how to get it work with Provider v4..let me know

    • @FilledStacks
      @FilledStacks  4 роки тому

      What are the differences from v3 besides the parameter name updates?

    • @raykoster3562
      @raykoster3562 4 роки тому

      @@FilledStacks they changed from SingleChildCloneableWidget to SingleChildWidget and it seems to causing issues with hot reload with this Architecture. I migrated to v4 and after a hot reload the Instance of the Providers are different, so all variables are null when accessing from a different view model. github.com/rrousselGit/provider/issues/237. In my case iam initiating some Data in my "HomeView", and in a other BaseWidget which using the same service to access the initiated Data, the Data is null. Ive checked the HashCodes of the Service Instances and they are different. After a downgrade to 3.2.0 its working quite well. Maybe you can have a look at it and provide a short way to fix it?

    • @raykoster3562
      @raykoster3562 4 роки тому

      interesting, maybe i found a solution for it.
      Before:
      ProxyProvider(
      update: (context, foo, bar >) =>
      bar(foo: foo),
      ),
      After
      ProxyProvider(
      create: null
      update: (context, foo, bar >) => bar ??
      bar(foo: foo),
      ),

  • @vOnez212
    @vOnez212 4 роки тому

    Hello. I hope you can help with this please and thank you =) I have FirebaseAuthService which has `Future get getUser => _firebaseAuth.currentUser();` and `Stream get user => _firebaseAuth.onAuthStateChanged;`. onAuthStateChanged Streams user after authentication or any updates. I also have FirebaseStorageService which has a constructor signature that requires user id - `FirebaseStorageService({@required this.uid}) : assert(uid != null);`. How can I instantiate the FirebaseStorageService in the provider_setup.dart file (you show around 5:00) immediately after FirebaseAuthService knows about the user? Thanks! And great videos!

    • @FilledStacks
      @FilledStacks  4 роки тому +1

      Pass a callback function to the FirebaseAuthService that takes the uid as a parameter. When the onAuthStateChanged firest execute the function and pass to it the ui. On the outside do a normal registration in the locator when the function fires.
      You can also use a Completer and return that as the future of your registeration call for authState. You can then return the function once your auth state has changed.

    • @vOnez212
      @vOnez212 4 роки тому

      @@FilledStacks Hey man. Thanks for the feedback. I ended up injecting the service into the storage service. The only thing I dont like is that I have to check if the user uuid defined before making requests that require it. Works for now. Will update if I find better option. Thanks!

  • @smokxx
    @smokxx 2 роки тому

    "Provider.value(value: Api())" - Provider library specifically says "DON'T use Provider.value to create your object."

    • @FilledStacks
      @FilledStacks  2 роки тому

      Maybe it says that now, but not 2 years ago when the package was created :D