-
Notifications
You must be signed in to change notification settings - Fork 12
/
task_data.dart
42 lines (33 loc) · 1 KB
/
task_data.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'package:flutter/foundation.dart';
import 'package:iamrick/models/task.dart';
import 'dart:collection';
class TaskData extends ChangeNotifier {
List<Task> _tasks = sampleTasks();
UnmodifiableListView<Task> get tasks => UnmodifiableListView(_tasks);
// List<Task> getTasks() => _tasks;
// Task getTask(int index) => _tasks[index];
int numberOfTasks() => _tasks.length;
void addTask(String text) {
_tasks.add(Task(text));
notifyListeners();
}
void toggleCheck(int index) {
_tasks[index].isCompleted = !_tasks[index].isCompleted;
notifyListeners();
}
void deleteTask(int index) {
_tasks.removeAt(index);
notifyListeners();
}
static List<Task> sampleTasks() {
return [
Task('Clear the walkers from the gate.'),
Task('Go over the inventory.'),
Task('Inspect the walls.'),
Task('Clean my revolver.'),
Task('Interrogate the newcomers.'),
Task('Plan the new supply routes.'),
Task('Give a motivational speech.'),
];
}
}