Skip to content

Commit 375b53d

Browse files
blueneogeogitbook-bot
authored andcommitted
GitBook: [master] 3 pages and one asset modified
1 parent 45a4db4 commit 375b53d

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed
45.4 KB
Loading

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [Shortcuts](guide/overview.md)
2121
* [Styling with CSS](guide/styling-with-css.md)
2222
* [Writing Reactive code](guide/writing-reactive-code.md)
23+
* [Untitled](guide/untitled.md)
2324

2425
## Shortcuts Reference
2526

guide/untitled.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Untitled
2+

guide/writing-reactive-code.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
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:
66

77
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 the reactive tag 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**
1111

1212
Our app will look like this:
1313

@@ -253,7 +253,7 @@ First lets set some example starter tasks. In **AppModel**, add some starter tas
253253

254254
{% code-tabs %}
255255
{% code-tabs-item title="app-model.dart" %}
256-
```text
256+
```dart
257257
// this.tasks = [];
258258
259259
this.tasks = [
@@ -269,7 +269,7 @@ To actually show the tasks on the **tasks-page**, we can iterate through them wi
269269

270270
{% code-tabs %}
271271
{% code-tabs-item title="task-page.pug" %}
272-
```css
272+
```c
273273
// #body(as='body')
274274
// center Here be tasks!
275275

@@ -418,6 +418,53 @@ The only real replacement is that we changed a simple \#body container into a re
418418

419419
![](../.gitbook/assets/screen-shot-2018-12-18-at-5.00.15-pm%20%281%29.png)
420420

421+
## Using computed properties
422+
423+
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:
426+
427+
{% code-tabs %}
428+
{% code-tabs-item title="tasks-page.pug" %}
429+
```css
430+
task-entry(flutter-view :task[Task] :model[TasksPageModel])
431+
card
432+
row
433+
.title(:text-decoration='model.taskTextDecoration(task)')
434+
| ${task.name}
435+
checkbox(:^value='task.done')
436+
```
437+
{% endcode-tabs-item %}
438+
{% endcode-tabs %}
439+
440+
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**:
441+
442+
{% code-tabs %}
443+
{% code-tabs-item title="lib/pages/taskspage/taskspage-model.dart" %}
444+
```dart
445+
import 'package:meta/meta.dart';
446+
import 'package:scoped_model/scoped_model.dart';
447+
import 'package:todolist/model/app-model.dart';
448+
449+
class TasksPageModel extends Model {
450+
TasksPageModel({@required this.app});
451+
452+
final AppModel app;
453+
454+
taskTextDecoration(Task task) {
455+
return task.done ? TextDecoration.lineThrough : TextDecoration.none;
456+
}
457+
}
458+
```
459+
{% endcode-tabs-item %}
460+
{% endcode-tabs %}
461+
462+
Now completed tasks look more completed:
463+
464+
![done means done!](../.gitbook/assets/screen-shot-2018-12-19-at-4.10.57-pm.png)
465+
466+
## See the full example
467+
421468
This covers the basics of how to make any app react to your model changes.
422469

423470
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

Comments
 (0)