Giter VIP home page Giter VIP logo

Comments (3)

pyrossh avatar pyrossh commented on June 1, 2024 2

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.

brianegan avatar brianegan commented on June 1, 2024 1

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.

talksik avatar talksik commented on June 1, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.