FilledStacks / FilledStacks/flutter-tutorials

Is there any way to use viewModel in didUpdateWidget?

Open
#178 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
4.8k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

When the arguments received from the widget changed, we wanted to clear the existing listener for the pagingController and populate a new one. How can i do this?

```dart
@override
void didUpdateWidget(convariant MyWidget oldWidget) {
super.didUpdateWidget(oldWidget);

if (oldWidget.path != widget.path) {
_pagingController.removePageRequestListener(_pageRequestListener!);
_pageRequestListener = null;

_pageRequestListener = (pageKey) async {
// This is where we use viewModel.
}

_pagingController.addPageRequestListener(_pageRequestListener!);
_pagingController.refresh();
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names no repository file or test; start with the widget's didUpdateWidget override and the _pagingController listener setup shown here. Done would mean documenting how the viewModel is accessed when widget.path changes, including removal and re-registration of the listener and the refresh behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.