Comments (3)
Hmmm so thats how it is. Shouldn't this be in the docs. Anyways I prefer this approach even though it might not be the more performant one. Thanks.
from scoped_model.
Yep, that's expected. You need to pass through rebuildOnChange: true
as part of your call to ScopedModel.of
, or it will only grab the value the first time. I'm considering adding a listen
or on
method instead to make this a bit clearer.
E.g. you need to change this:
static TestModel of(BuildContext context) => ScopedModel.of<TestModel>(context);
to this:
static TestModel of(BuildContext context) =>
ScopedModel.of<TestModel>(context, rebuildOnChange: true);
from scoped_model.
@brianegan I was stuck on a really weird problem related to this.
I have a complicated model which has a big map of data. I was using this way of doing things
final linesModel =
ScopedModel.of<LinesModel>(context, rebuildOnChange: false);
final authUserModel =
ScopedModel.of<AuthUserModel>(context, rebuildOnChange: false);
final presenceModel =
ScopedModel.of<PresenceModel>(context, rebuildOnChange: true);
However, I was using the above outside of the build method and in a lifecycle method, and I have one of the rebuildOnChange set to true for presenceModel. Children of widgets in the build method changed something in the presenceModel and so the build method re-mounted.
So the observation is that even if you use this direct access way in a lifecycle method instead of descendent, and you put rebuildOnChange/listen as true, it causes the build method to run again and hence calling the initState of all children widget again.
However, my weird problem was that this caused an infinite loop in android but not on web. I was stuck on it for hours and can't figure out why on android, children widgets would keep remounting/their initstate kept getting called in an infinite loop as they were updating presenceModel data. I had to change the rebuildOnChange to false for android to stop the loop. However, in flutter run web/chrome, the infinite loop never happened.
Am I missing something fundamental about flutter? Or something fundamental about platforms? Or something fundamental about scoped_model specifically as it relates to web vs. android?
Please help, I'm really stuck on why flutter is inconsistent on both platforms. I chose flutter because I thought it would be super consistent.
from scoped_model.
Related Issues (20)
- Some widget don't refresh after calling notifyListener in flutter 1.22.1
- bloc model value fetch in init function not working
- can't run
- can't run
- Error: Could not find the correct ScopedModel.
- Testing when using scopedModelDescendant HOT 2
- 单独抽离一个方法 如何修改值?
- 不继承 ScopedModelDescendant() 如何修改值?
- void initState() 方法里如何修改值?
- Not Working error
- Target of URI doesn't exist: 'package:scoped_model/scoped_model.dart'.
- Publish null safe stable version
- Error: Could not find the correct ScopedModel. To fix, please: * Provide types to ScopedModel<MyModel> * Provide types to ScopedModelDescendant<MyModel> * Provide types to ScopedModel.of<MyModel>() * Always use package imports. Ex: `import 'package:my_app/my_model.dart'; If none of these solutions work, please file a bug at:
- Error: Could not find the correct ScopedModel. To fix, please: * Provide types to ScopedModel<MyModel> * Provide types to ScopedModelDescendant<MyModel> * Provide types to ScopedModel.of<MyModel>() * Always use package imports. Ex: `import 'package:my_app/my_model.dart'; If none of these solutions work, please file a bug at:
- Exception has occurred. ScopedModelError (Error: Could not find the correct ScopedModel.
- scoped_model issues HOT 6
- Scoped Model - not working after go back to previous page
- Model notifyListeners closes EndDrawer
- ScopedModel
- scoped_model.of() issue HOT 1
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 scoped_model.