Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested models cannot update UI #867

Closed
freatraum opened this issue Mar 4, 2024 · 1 comment
Closed

Nested models cannot update UI #867

freatraum opened this issue Mar 4, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@freatraum
Copy link

freatraum commented Mar 4, 2024

Description
I have created four models: appModel, TrackModel, ClipModel, and NoteModel, which are nested (Details are in my repositories: editor_demo.). When I use methods in ClipModel to update data within ClipModel, the UI is not updated.

At line 54 in lib/views/track_view.dart of the repository editor_demo, the UI can be updated normally.

  onPanDown: (details) {
    SingingClip singingClip = SingingClip();
    appModel
      ..setSelectedTrackId(widget.track.id)
      ..setSelectedClipId(singingClip.id);
    singingClip.setStart(details.localPosition.dx);
    singingClip.setClipStart(details.localPosition.dx);
    singingClip.setName("New Clip");
    singingClip.setLength(120);
    widget.track.insertClip(singingClip);
  },

However, at line 46 in lib/views/track_view.dart of the repository editor_demo, the UI does not update normally. I have to use setState to force an update.

  onPanUpdate: (details) {
    var clip = widget.track.findClipById(appModel.selectedClipId);
    var deltaX = details.localPosition.dx - clip.start;
    if (deltaX > 120) {
      clip.setLength(deltaX);
      setState(() {});
    }
  },

Is this due to the complexity of my model? How can I solve this problem?

@freatraum freatraum added bug Something isn't working needs triage labels Mar 4, 2024
@rrousselGit
Copy link
Owner

For help request, you should instead ask on StackOverflow/Discord.

TL;DR, you need to use a ChangeNotifierProvider, and call notifyListeners() when you update the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants