You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -463,11 +463,81 @@ Now completed tasks look more completed:
463
463
464
464

465
465
466
+
## Monitoring the state lifecycle
467
+
468
+
You may need to _**initialize**_ some things in your **view-model** when the state of your layout starts, and _**free**_ those resources when the state is disposed of. In that case, **use a**[**lifecycle**](../reference/tag-shortcuts.md#lifecycle)**widget**. It is part of the flutter-view-tools library.
469
+
470
+
For example, let's say your **view** has a [**ListView**](https://docs.flutter.io/flutter/widgets/ListView-class.html) widget with a long list and you want to be able to load more items when you scroll near the bottom.
471
+
472
+
This requires we create a [**ScrollController**](https://docs.flutter.io/flutter/widgets/ScrollController-class.html) in the **view-model** and pass it to the [**ListView**](https://docs.flutter.io/flutter/widgets/ListView-class.html)****in the **view**. We can then listen to the [**ScrollController**](https://docs.flutter.io/flutter/widgets/ScrollController-class.html) and react when the scrollposition is very low. Finally, when the **view** is disposed of, we also want our listener to be removed.
473
+
474
+
In the todo app we can do this as follows in the **view**:
task-entry(for='task in model.app.tasks' :task='task' :model='model')
483
+
```
484
+
{% endcode-tabs-item %}
485
+
{% endcode-tabs %}
486
+
487
+
At line **2** we add the [**lifecycle**](../reference/tag-shortcuts.md#lifecycle) widget with handlers for the init and dispose events, and pass them along to the **view-model**.
488
+
489
+
At line **3** we pass the scrollController of the view-model to the list, so we can monitor the scrolling position.
490
+
491
+
The **view-model** needs to store the scrollController, initialize it and dispose of it:
At lines **13** and **17** we add the **init** and **dispose** methods that are called by the lifecycle widget. These will start and stop listening to our scrollController.
533
+
534
+
Finally at line **21** we have an **onScroll** method that actually checks the scroll position and loads more entries.
535
+
466
536
## See the full example
467
537
468
-
This covers the basics of how to make any app react to your model changes.
538
+
This covers the basics of how to structure a reactive app with flutter-view, ScopedModel and the flutter-view-tools.
469
539
470
-
Of course our todo app is still incomplete,however with this you should be able to understand the full implementation. See [the full example](../get-started/examples.md#todolist) with [source code](https://github.com/flutter-view/examples/tree/master/todolist) for a full implementation of this todo app. Notable additions there are:
540
+
Of course our todo app is still incomplete,however you now should be able to understand the full implementation. See [the full example](../get-started/examples.md#todolist) with [source code](https://github.com/flutter-view/examples/tree/master/todolist) for a full implementation of this todo app. Notable additions there are:
471
541
472
542
* an add-task-dialog view that lets you enter a new task
0 commit comments