OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library model; | 5 library model; |
6 | 6 |
7 class ViewModel { | 7 class ViewModel { |
8 bool isVisible(Todo todo) => todo != null && | 8 bool isVisible(Todo todo) => todo != null && |
9 ((showIncomplete && !todo.done) || (showDone && todo.done)); | 9 ((showIncomplete && !todo.done) || (showDone && todo.done)); |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 int get doneCount { | 35 int get doneCount { |
36 int res = 0; | 36 int res = 0; |
37 todos.forEach((t) { if (t.done) res++; }); | 37 todos.forEach((t) { if (t.done) res++; }); |
38 return res; | 38 return res; |
39 } | 39 } |
40 | 40 |
41 int get remaining => todos.length - doneCount; | 41 int get remaining => todos.length - doneCount; |
42 | 42 |
43 void clearDone() { | 43 void clearDone() { |
44 todos = todos.filter((t) => !t.done); | 44 todos = todos.where((t) => !t.done).toList(); |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 final AppModel app = new AppModel(); | 48 final AppModel app = new AppModel(); |
49 | 49 |
50 class Todo { | 50 class Todo { |
51 String task; | 51 String task; |
52 bool done = false; | 52 bool done = false; |
53 | 53 |
54 Todo(this.task); | 54 Todo(this.task); |
55 | 55 |
56 String toString() => "$task ${done ? '(done)' : '(not done)'}"; | 56 String toString() => "$task ${done ? '(done)' : '(not done)'}"; |
57 } | 57 } |
OLD | NEW |