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
Copy file name to clipboardExpand all lines: guide/writing-reactive-code.md
+52-5Lines changed: 52 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@
5
5
This guide will show you how we recommend you build a simple reactive app with an [MVVM approach](https://en.wikipedia.org/wiki/Model–view–viewmodel) using the ReactiveWidget and flutter-view. In essence building a reactive app in flutter-view always works the same:
6
6
7
7
1.**handle events from your views on the view-model**
8
-
2.**have the view-model call your business logic for actions**
9
-
3.**have those actions update your business model**
10
-
4.**have your views use thereactivetag to listen for any updates**
8
+
2.**have the view-model call your business model for actions**
9
+
3.**have those actions update your business model data**
10
+
4.**have your views use the**[**reactive**](../reference/tag-shortcuts.md#reactive)**tag to listen for any updates**
11
11
12
12
Our app will look like this:
13
13
@@ -253,7 +253,7 @@ First lets set some example starter tasks. In **AppModel**, add some starter tas
253
253
254
254
{% code-tabs %}
255
255
{% code-tabs-item title="app-model.dart" %}
256
-
```text
256
+
```dart
257
257
// this.tasks = [];
258
258
259
259
this.tasks = [
@@ -269,7 +269,7 @@ To actually show the tasks on the **tasks-page**, we can iterate through them wi
269
269
270
270
{% code-tabs %}
271
271
{% code-tabs-item title="task-page.pug" %}
272
-
```css
272
+
```c
273
273
// #body(as='body')
274
274
// center Here be tasks!
275
275
@@ -418,6 +418,53 @@ The only real replacement is that we changed a simple \#body container into a re
Often you may need to calculate things for your presentation that are not possible with just simple layout presentation logic. Instead **you use the view-model to compute values for your view**.
424
+
425
+
For example, let's have the tasks that are completed have their title text decorated with strike-through. And as an exercise, let's have the text-decoration computed on the view-model instead of in the view. Update the task-entry in tasks-page.pug:
At line 4 we have added a computed [**text-decoration**](../reference/css-properties.md#box-shadow-13) property. It starts with `:` so it will use the result of the expression we pass. This expression is **model.taskTextDecoration\(task\)**. We want this expression to return [**TextDecoration.lineThrough**](https://docs.flutter.io/flutter/dart-ui/TextDecoration/lineThrough-constant.html) if our passed current task is done. Let's add this method to the **TasksPageModel**:

465
+
466
+
## See the full example
467
+
421
468
This covers the basics of how to make any app react to your model changes.
422
469
423
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:
0 commit comments