Comments (1)
Actually thinking about it more made me realize it is definitely not the best idea to call this action from Widget's build
function for various reasons
- Flutter calls Widget's
build
multiple times during its lifetime and it is not ideal to do something as heavy as a network call every timebuild
is called. - A way to overcome point 1 above is to guard it in some condition, but really what could be a better condition in this case? Either maintain flags that tell you if this call was previously made, if yes, do not make another call or check in the
state
and if data isnull
or empty, make a call. - Using flags could get really messy really fast and then you have to be extremely careful flipping those at various places.
- Checking in
state
fornull
or empty data isn't ideal either causenull
or empty data could be legitimate states. It does not always mean that network call was never made.
I think the best approach would be that the store (MessageStore
in this example) also listens to user auth state changes and as soon as the user is logged in, this store also receives an action callback and kickstarts the network fetch instead of waiting until widget does it.
This approach works well in this case but also leaves a question, what if this MessageStore
were to depend on some data from UserStore
? Meaning that both UserStore
and MessageStore
listen to same action callback but for MessageStore
to react to that action callback, it needs something from UserStore
. In this case how do you make sure that UserStore
always finishes its execution before MessageStore
starts its execution? I believe React's Flux has API waitFor()
from flutter_flux.
Related Issues (20)
- flutter_flux is out of date HOT 6
- Dispose override
- Confused by StoreWatcher HOT 2
- How to change TextField text from Store? HOT 4
- Guidance please HOT 2
- Will this be maintained? HOT 3
- Wrong flutter_flux code when pulled down from Dart package HOT 2
- Update ios and android build configs for Flutter Beta
- Is it okay to update widget's store in action callback? HOT 3
- Call setState inside StoreWatcher HOT 2
- Trigger on action with async functions does not trigger HOT 2
- StoreWatcherMixin Widget not rebuilding HOT 2
- triggerOnConditionalAction parameter type error HOT 4
- Outdated SDK version HOT 2
- how to listen to similar stores with different arguments HOT 1
- StoreWatcherMixin can't be used as mixin because it extends a class other than Object HOT 5
- Method listening to an action gets called multiple times HOT 4
- Flutter Web Support ? HOT 1
- removed unused dart:async
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_flux.