Pragmatic State Management in Flutter (Google I/O'19)
Why Stack Overflow recommends it
Stack Overflow users link it whenever a Flutter question is really about state management, as the official explanation of lifting state up and using Provider instead of calling into widgets or using global variables.
Recommended by 26 people across 23 different months, 2018 to 2022.
What it is
A Google I/O 2019 session by Filip Hracek and Matt Sullivan from the Flutter team on structuring app state in a declarative UI framework. It walks through Flutter's own app with live data and compares the main state management approaches, ending with a concrete solution based on Provider.
What people said
Strong rec Gabber235 · 2020-06 · Stack Overflow · on “Flutter Error : Could not find the correct Provider<Cart> above this ProductLandingPage Widget”
The idea of Provider is to lift the state management above the widgets so different children can easily access its state. So it would be helpful if you moved the HTTP request from the widget tree (where it will be called every time the UI updates, so users use more bandwidth than needed) to a provider that is created above the tree. Therefore the state doesn't need to passed around from widget to widget. Try watching this amazing talk from the flutter team to get a better understanding of how to use provider: [this video] Bdw read this StackOverflow answer about why .value isn't what you desire: How to deal with unwanted widget build? [LINK] So you should make the app like this void main() => run
Recommends Willy · 2019-03 · Stack Overflow · on “Flutter: Where to add listeners in StatelessWidget?”
You shouldn't. Not handling variables that might have their values modified is the very purpose of a Stateless [LINK] widget: A stateless widget never changes. UPDATE : I think this is a problem of understanding Flutter's state management concepts. This new recommended way [this video] by the Flutter team should clear some confusions.
Recommends Marcel · 2019-05 · Stack Overflow · on “Use variable as Global variable in Flutter”
Wonderful, you just discovered a fundamental computer science problem: state management! There are a lot of ways to do state management in Flutter and I really recommend you check out the Flutter state management talk at this year's Google I/O [this video] , where they outline the pros and cons of the different ways of handling state in Flutter. Just for the sake of it, here's one possible way of doing it pragmatically: You could just add the datosusuario as a constructor parameter to your Home widget, like so: class Home extends StatelessWidget { Home({ @required this.datasusuario, }); final datasusuario; @override Widget build() { // here you can use the datasusuario } } and then pass it to the
Recommends Leoog · 2019-05 · Stack Overflow · on “How to call setState from other file Dart”
I advise you use Provider as it was just recently recommended by the Google team as the best method. Provider will make sure you keep your code clean no matter how big your project gets. It's like ScopedModel but on steroids. Flutter I/O presentation by the Flutter team: [this video] Package: [LINK]
Recommends Aaron Saunders · 2019-06 · Stack Overflow · on “How to send data between tabs in Flutter?”
I believe the Provider is the recommended method for managing state in Flutter Application and was presented at Google IO and is at the top of the stack for state management in the Flutter Documentation on State Management [LINK] Video from GoogleI/O Pragmatic State Management in Flutter (Google I/O'19) [this video] service as my provider... import 'dart:collection'; import 'package:flutter/material.dart'; class Item { String name; num price; Item(this.name, this.price); } class CartModel extends ChangeNotifier { /// Internal, private state of the cart. final List<Item> _items = []; /// An unmodifiable view of the items in the cart. UnmodifiableListView<Item> get items => UnmodifiableListView(_it
Recommends HBG · 2019-07 · Stack Overflow · on “How to call into a flutter widget's state from the widget”
I could do with seeing more of your code to get a better idea of how to solve your specific issue but it appears that the Flutter documentation will help you in some regard, specifically the section on Lifting state up [LINK] : In Flutter, it makes sense to keep the state above the widgets that use it. Why? In declarative frameworks like Flutter, if you want to change the UI, you have to rebuild it. …it’s hard to imperatively change a widget from outside, by calling a method on it. And even if you could make this work, you would be fighting the framework instead of letting it help you. It appears you're trying to fight the framework in your example and that you were correct to be apprehensiv
Recommends Sergey Zabelnikov · 2019-09 · Stack Overflow · on “Get the built child of an existant StreamBuilder()”
You could reach a child of StreamBuilder, but this is fighting with framework instead of using it. You could easily make this logic by mutating widget's State and reacting to this change inside your StreamBuilder's child. Additionally you can do this inside your Bloc to keep everything clean. This talk from Google IO can help a lot [this video]
Recommends Mohamed Elrashid · 2019-09 · Stack Overflow · on “Controlling multiple widgets of same type while avoiding a list of GlobalKeys”
look good, you can also use *** provider [LINK] *** or *** rxdart [LINK] *** , i recommand *** provider [LINK] *** , here some videos *** Pragmatic State Management in Flutter (Google I/O'19) - YouTube [this video] *** & *** Pragmatic State Management Using Provider (The Boring Flutter Development Show, Ep. 24) - YouTube [LINK] ***
Recommends otavio1992 · 2020-01 · Stack Overflow · on “How to use detect changes in elements of an array using provider?”
I started developing my first app with flutter and I have some questions. I have a screen that contains a Horizontal ListView where each item represents a month and occupy the entire screen. Each item is another list of itens. It's basically a list showing expenses for every month. I'm controlling state using Provider, and I'm having trouble to detect changes in a month. For example, I'm in january, but I added an expense in february, so the february item must detect the change and rewrite. I haven't been able to do it so far. Here is the screenshots of the app: [LINK] [LINK] I have a provider that has an array of "Periods". And a "Period" is a class that represents a month, and contains an
Recommends TuMahler · 2020-03 · Stack Overflow · on “Flutter: Update a widget without using ValueKey”
If you find that you need to access _order data in other widgets, you might want to take a look at Provider [LINK] . Provider will allow you to manage the state across widgets fairly easily. A good video overview of it can be found here [this video]