New post on /r/flutterdev subreddit:
<b>State Management could have never been easier!</b>
One simple approach.
Design a widget tree with respect to certain variables and then just update parts of your widget tree as per your requirements. That's all you need to design a dynamic UI in Flutter.
How can one update/rebuild a part of them at ease? That's exactly what the below plugin is for.<a href="
https://pub.dev/packages/notifier_plugin">
https://pub.dev/packages/notifier_plugin</a>Notifier n = Notifier();
int i = 0;// [...Widget Tree...]
FlatButton(
child: n - ()=>Text(i.toString()) // Attaching the Notifier to a part of the widget tree
onTap: (){
++i;
n(); // All the widgets attached to this Notifier get re-built
}
)
// [...]While this might seem like a something a bit simpler than what currently exists, it's real power can only be felt while actually developing UI keeping the above approach in mind.One could even pass a value to another corner of the app with the help of a `ValNotifier`,ValNotifier v = ValNotifier(initalVal: 0);
// [...Some Widget Tree...]
FlatButton(
child: v - (value)=>Text(value.toString()),
onTap: ()=>v(v.val+1)
)
// [...]
// Note: Both Notifier and ValNotifier can work with multiple widgetsJust want to update a widget tree without explicitly defining it? The plugin has got you
covered.int i = 0;// [...Widget Tree...]
~(n) => FlatButton(
child: Text(i.toString()) // Attaching the Notifier to a part of the widget tree
onTap: (){
++i;
n(); // All the widgets attached to this Notifier get re-built
}
)
// [...]A ValNotifier can be obtained in a similar manner by adding an extra parameter,
~(n,v)=>SomeWidgetTree()If this still sounds unrelatable, then just imagine practically implementing some UI logic without really thinking about any other concept....just the above approach. (Design with respect to certain variables and then update as and when needed and see the ease it will provide...the ease would be felt to such an extent that only the app's logic would be there in the developer's mind while using the approach)While the basic features of the plugin will cover most of needs, here's a list of just few of the features the plugin otherwise offers,Perform (foward/reverse/circular) animations with the help of a ValNotifier/TweenNotifier (just specify the start and end value and the duration [and curve] and the plugin shall handle the rest for you)Performing http requests with common parameters have got easier than ever! Every time you request from a HttpNotifier, you'll just have to overwrite the parameters that were previously cached or send a request directly with them, thereby reducing the overall boiler-plate code.Almost any common listenable object (ChangeNotifier, ValueNotifier, Stream(Controller), Notifier, ValNotifier, ...(including controllers)) can be easily be connected to a widget for updates. So whenever the listenable object gets notified or receives a new value, the connected widget will automatically rebuild that part of the widget tree without any hassles.A few examples:changeNotifier - () => Text("Will surely accept no parameters"),
valueNotifier - (value) => Text("Will surely accept a single parameter ($value)"),
stream - (snapshot) => Text(snapshot.hasError?"Error: ${snapshot.error}":"Data: ${<a href="
https://snapshot.data">
snapshot.data</a>}")And since a controller is very likely to be a ChangeNotifier or ValueNotifier,textEditingController - (textEditingValue) => Text(textEditingValue.text), // ValueNotifier
scrollController - () => Text(scrollController.offset.toString()), // ChangeNotifierEver felt that dealing with Future(s) or async objects is not that intuitive or has too much code to deal with? The plugin has solved that problem too.future - (snapshot)=>DealWithIt(snapshot)
WFuture(future) - (data)=>Text(data.toString()) // Loading and error widget were predefinedTo know more about the other features offered by the plugin, head over to the links given below.Plugin: <a href="https:/…