Breakdown — Flutter @i/o 2018 (Part Two)
If you can dream it, you can do it.
All in one Flutter Resource: https://flatteredwithflutter.com/
This is the concluding part of my earlier post, Flutter @i/o 2018 .
Presenters laid focus on handling states with flutter :
- Flutter & state
- State & the widget tree
- Reactive with streams
The discussion started with incrementer app (out of box app which comes with flutter). On click of the floating button, count was displayed. The count variable initially was kept with global scope (not recommended by presenter), later passed in as parameter to the function and accessed as
Passing States…(State and the Widget Tree)
- How to access state that is not in the widget we build ?
- How to notify other widgets for rebuilding?
Here comes inherited widgets…
How to use them :
But, as the state is declared final, it becomes little hard (by introducing boiler plates) to mutate state using inherited widgets.
Scoped Model was introduced….
- Available as external package
- Built on top of Inherited Widget
- Access, update and mutate state
Whenever we have a descendant widget (ScopedModelDescendant), they observe or listen for the state changes and get rebuild.
Top-level widget (MaterialApp) is replaced by ScopedModel which takes a model(CartModel) and a child (material app in this case).
ScopedModel( model : CartModel(), child : MaterialApp())
CartButton widget changed to ScopedModelDescendant which takes a builder function.
One important property of ScopedModelDescendant : if you don’t want to rebuild a certain widget, for instance on click of cloth item only the cart count widget should be rebuild and not the entire cloth section, we can do it as
Reactive with Streams….
Reactive architecture in flutter was focussed…
Sinks in, streams out..(sinks are input, streams are output)
Lastly, dart streams and rx.package were highly recommended by the presenters.
The Flutter Pub is a medium publication to bring you the latest and amazing resources such as articles, videos, codes, podcasts etc. about this great technology to teach you how to build beautiful apps with it. You can find us on Facebook, Twitter, and Medium or learn more about us here. We’d love to connect! And if you are a writer interested in writing for us, then you can do so through these guidelines.