Skip to content

Instantly share code, notes, and snippets.

View corelmax's full-sized avatar

corelmax corelmax

  • Billme Venture Co., Ltd.
  • Bangkok, Thailand
View GitHub Profile
We couldn’t find that file to show.
{"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"}]}
import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';
class TodoList extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return TodoListState();
}
}
class Todo {
String id = Uuid().v4();
String title = 'New todo item';
bool isDone = false;
Todo();
}
@@ -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: [
@@ -8,7 +8,14 @@
}
}
-class TodoListState extends State<TodoList> {
+class TodoListState extends State<TodoList> {
+ Map<String, Todo> todos = {};
+
+ void addTodo(Todo todo) {
+ setState(() {
@@ -61,7 +61,7 @@
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
- // create todo item here
+ addTodo(Todo());
}
),
);
@@ -18,6 +18,12 @@
});
}
+ void updateTodo(Todo todo) {
+ setState(() {
+ todos[todo.id] = todo;
+ });
+ }
+
@@ -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(
@@ -24,6 +24,12 @@
});
}
+ void removeTodoById(String id) {
+ setState(() {
+ todos.remove(id);
+ });
+ }
+