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/configuring-flutter-view.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,16 @@ For example, if you want to use FlatButton when you use the button tag:
88
88
89
89
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\).
90
90
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:
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**:
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 setafont 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:
0 commit comments