7/2/2023 0 Comments Flutter provider in initstate![]() ![]() Maybe itâs just me, but when working âstep by stepâ, I work top to bottom through the code. aslam mac Follow As we all know that Provider is the best known state management package available for flutter. Iâm really hoping I can finally get a handle on this promising language as a result.įurther to this, I had to âcheatâ and look at the Appendix for the âstep by step answersââ¦and still got it wrong. Use data from Provider during initState () in Flutter. You can use this code: Provider.of(context, listen: false).![]() ![]() I appreciate all the work that has gone in to this book, especially the numbered breakdowns after most of the code blocks to explain whatâs happening. In initState all the of(context) things dont work correctly, because the widget is not fully wired up with every thing in initState. I think that at least introducing the concept before challenging the concept would be more helpful, though.Äespite work through Dart Apprentice first, Iâm still trying to understand how a lot of this is supposed to be structured, so I can only imagine how absolutely fresh coders may be struggling with this. For example, we can use ref. It is commonly used inside functions triggered by user interactions. The ref.read method is a way to obtain the state of a provider without listening to it. Yes, there is a balance trying to be struck between absolute neophyte coders and experienced developers with this book, and that is a challenge itself. Using ref.read to obtain the state of a provider. (And, personally, are thoroughly confusing) Subclasses of State should override initState to perform one-time initialization that depends on the BuildContext or the widget, which are available as the context and widget properties, respectively, when the initState method is called. Most probably that data would had to come from ctor (meaning this widget should be inside a Consumer). 1 Answer Sorted by: 2 As from the official documentation: The framework calls initState.Telling readers to go read the Flutter docs doesnât help, either, as those have no examples to help put things in context. If you need data for this page in initState, you're doing it wrong. Actual usage of initState() doesnât appear until Chapter 6. We havenât seen initState() yet, except in a very high-level mention in Chapter 4. I understand that a challenge is meant to stretch oneâs abilities, but it feel like Chapter 5âs Challenge 1: Add a scroll listener comes too soon. ![]()
0 Comments
Leave a Reply. |