@override
initState() {
super.initState();
// Add listeners to this class
cartItemStream.listen((data) {
_updateWidget(data);
});
}
didChangeDependencies()
The didChangeDependencies method is called immediately after initState on the first time the widget is built.
It will also be called whenever an object that this widget depends on data from is called. For example, if it
relies on an InheritedWidget, which updates. build is always called after didChangeDependencies is called,
so this is rarely needed. However, this method is the first change you have to call
BuildContext.inheritFromWidgetOfExactType. This essentially would make this State 'listen' to changes on a
Widget it's inheriting data from. The docs also suggest that it could be useful if you need to do network calls
(or any other expensive action) when an InheritedWidget updates.
Dostları ilə paylaş: