Skip to content

Commit 91a5279

Browse files
blueneogeogitbook-bot
authored andcommitted
GitBook: [master] 2 pages and one asset modified
1 parent 5d54545 commit 91a5279

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed
46 KB
Loading

guide/configuring-flutter-view.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ For example, if you want to use FlatButton when you use the button tag:
8888

8989
In Flutter, some widgets expect a child parameter, while others expect a children parameter. With multiChildClasses you can list classes that require the children parameter \(otherwise child is used\).
9090

91-
Default value:
91+
Note: in case an entry is not in the default list, you can also pass the children via the array tag. For example:
92+
93+
```css
94+
column
95+
array(as='children')
96+
row first child
97+
row second child
98+
```
99+
100+
Default values:
92101

93102
```javascript
94103
multiChildClasses: [

guide/writing-reactive-code.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,74 @@ Now that we have wired up all the basic parts, we can run our app:
229229

230230
![](../.gitbook/assets/screen-shot-2018-12-15-at-11.20.06-pm.png)
231231

232+
## Showing data from the model
232233

234+
Now that the basic framework is in place, **we can use flutter-view to present model data it in the view**.
235+
236+
In the case of our app, we want to show the tasks from the **AppModel** in our **tasks-page**. When there are no tasks, we want to show a message that encourages someone to create the first task. When there are already tasks, we want to show the list.
237+
238+
First lets set some example starter tasks. In **AppModel**, add some starter tasks:
239+
240+
```text
241+
// this.tasks = [];
242+
this.tasks = [
243+
Task(name: 'Do the dishes'),
244+
Task(name: 'Cut the grass'),
245+
];
246+
247+
```
248+
249+
To actually show the tasks on the **tasks-page**, we can iterate through them with the flutter-view [**for property**](flow-control.md#for)**:**
250+
251+
```css
252+
// #body(as='body')
253+
// center Here be tasks!
254+
#body(as='body')
255+
list-view
256+
.task(for='task in model.app.tasks') ${task.name}
257+
```
258+
259+
Now after hot reloading you should see the two tasks, as two lines of text.
260+
261+
In line 5, we are creating an array of .task Containers, one for each element in **TaskPageModel.app.tasks.** In each container we put a text with the task name.
262+
263+
To clean up the presentation a bit, we can create a view that creates a single task, and repeat that instread. Add the following flutter-view code in **tasks-page.pug**:
264+
265+
```css
266+
task-entry(flutter-view :task[Task] :model[TasksPageModel])
267+
card
268+
row
269+
.title ${task.name}
270+
checkbox(:^value='task.done')
271+
```
272+
273+
This renders a single task entry. Now we can use it in the body:
274+
275+
```css
276+
#body(as='body')
277+
list-view
278+
task-entry(for='task in model.app.tasks' :task='task' :model='model')
279+
```
280+
281+
In line 3, we are again using for to repeat the tag for each task. A **task-entry** takes two parameters: the task and the model, so we pass both.
282+
283+
Finally, let's add some styling. Create a tasks-page.sass next to tasks-page.pug, and put in the following styling:
284+
285+
```css
286+
task-entry
287+
card
288+
row
289+
main-axis-alignment: space-between
290+
.title
291+
margin-left: 20
292+
font-size: 20
293+
```
294+
295+
Please compare this sass styling with the pug task-entry we added. The Row in task-entry gets assigned a space between main-axis-alignment, which pushes the text to the left and the checkbox to the right. Besides that we set a font size and margin to the **.title** Container.
296+
297+
See the generated task-page.dart to see what actually is being generated in Dart, by taking the Pug and applying the styles with shortcuts. The result looks like this:
298+
299+
![](../.gitbook/assets/screen-shot-2018-12-18-at-4.20.01-pm.png)
233300

234301

235302

0 commit comments

Comments
 (0)