diff --git a/lib/check_list.dart b/lib/check_list.dart index c8ec363..2f1d250 100644 --- a/lib/check_list.dart +++ b/lib/check_list.dart @@ -42,6 +42,10 @@ class _CheckList extends State { }); } + void _removeItem(data.Check item) async { + DBHelper.dbHelper.deleteItem(item); + } + void _updateItem(data.Check item) async { DBHelper.dbHelper.updateItem(item); } @@ -88,7 +92,43 @@ class _CheckList extends State { child: ListView.builder( itemCount: list.length, itemBuilder: (context, index) { - return Card( + return Dismissible( + key: Key(list[index].id.toString()), + confirmDismiss: (direction) async { + if (direction == DismissDirection.startToEnd) { + setState(() { + _removeItem(list[index]); + list.removeAt(index); + }); + return true; + } + setState(() { + list[index].value = !list[index].value; + }); + return false; + }, + secondaryBackground: Container( + child: Container( + color: Colors.blue, + child: Row(children: const [ + Spacer(), + Padding( + padding: EdgeInsets.all(10), + child: Icon(Icons.check)), + ])), + ), + background: Container( + child: Container( + color: Colors.red, + child: Row(children: const [ + Padding( + padding: EdgeInsets.all(10), + child: Icon( + Icons.delete_forever, + )), + Spacer(), + ])), + ), child: CheckboxListTile( title: TextFormField( enabled: (listData != null && diff --git a/lib/db_helper.dart b/lib/db_helper.dart index 33ec031..8d5fb0f 100644 --- a/lib/db_helper.dart +++ b/lib/db_helper.dart @@ -83,6 +83,12 @@ class DBHelper { return db.insert("Item", item.toMap()); } + Future deleteItem(data.Check item) async { + Database db = await database; + + return db.delete("Item", where: 'id = ?', whereArgs: [item.id]); + } + Future updateItem(data.Check item) async { Database db = await database;