-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmodels.dart
55 lines (45 loc) · 1.14 KB
/
models.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
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:flutter/material.dart';
// TODO: Add 'reminder' and 'due date' fields.
class Todo {
final String title;
final String? description;
final Priority priority;
final bool isDone;
const Todo({
required this.title,
this.description,
this.priority = Priority.none,
this.isDone = false,
});
}
enum Priority {
high(displayName: 'High Priority', color: Colors.red),
medium(displayName: 'Medium Priority', color: Colors.orange),
low(displayName: 'Low Priority', color: Colors.blue),
none(displayName: 'No Priority');
const Priority({
required this.displayName,
this.color,
});
final String displayName;
final Color? color;
}
class TodoList extends ChangeNotifier {
final List<Todo> _todos = [];
int get length => _todos.length;
Todo operator [](int index) => _todos[index];
void add(Todo todo) {
_todos.insert(0, todo);
notifyListeners();
}
void toggle(int index) {
final todo = _todos[index];
_todos[index] = Todo(
title: todo.title,
description: todo.description,
priority: todo.priority,
isDone: !todo.isDone,
);
notifyListeners();
}
}