This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36","platform":"MacIntel","cookieEnabled":true,"deviceMemory":8,"doNotTrack":null,"language":"en-US","languages":["en-US","en","th","la"],"connectionType":"4g","connectionDownlink":1.5,"connectionRtt":150,"windowWidth":1287,"windowHeight":798,"pageWidth":1271,"pageHeight":782,"safeWidth":1287,"safeHeight":798,"host":"localhost:3000","url":"http://localhost:3000/index.html","origin":"http://localhost:3000","path":"/index.html","protocol":"http:","queryString":"","referrer":"","charset":"UTF-8","clientId":"123","userUniqueId":"4aa7da06-0676-453a-a2ad-d0176624fa70","requireConsents":[{"clientId":"1234","consentId":"1111","url":"https://localhost"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:uuid/uuid.dart'; | |
class TodoList extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() { | |
return TodoListState(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Todo { | |
String id = Uuid().v4(); | |
String title = 'New todo item'; | |
bool isDone = false; | |
Todo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -14,12 +14,13 @@ | |
return ListView.builder( | |
itemCount: todos.length, | |
itemBuilder: (context, index) { | |
+ var item = todos.entries.elementAt(index).value; | |
return Card( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Row( | |
children: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -8,7 +8,14 @@ | |
} | |
} | |
-class TodoListState extends State<TodoList> { | |
+class TodoListState extends State<TodoList> { | |
+ Map<String, Todo> todos = {}; | |
+ | |
+ void addTodo(Todo todo) { | |
+ setState(() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -61,7 +61,7 @@ | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () { | |
- // create todo item here | |
+ addTodo(Todo()); | |
} | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -18,6 +18,12 @@ | |
}); | |
} | |
+ void updateTodo(Todo todo) { | |
+ setState(() { | |
+ todos[todo.id] = todo; | |
+ }); | |
+ } | |
+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -34,13 +34,14 @@ | |
child: Row( | |
children: [ | |
- Checkbox(value: false, onChanged: (value) { | |
- // we will update todo item here | |
+ Checkbox(value: todo.isDone, onChanged: (value) { | |
+ todo.isDone = value; | |
+ updateTodo(todo); | |
}), | |
Expanded( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -24,6 +24,12 @@ | |
}); | |
} | |
+ void removeTodoById(String id) { | |
+ setState(() { | |
+ todos.remove(id); | |
+ }); | |
+ } | |
+ |
OlderNewer