removable items
This commit is contained in:
parent
14c23baa75
commit
7b1f6860e3
|
|
@ -42,6 +42,10 @@ class _CheckList extends State<CheckList> {
|
|||
});
|
||||
}
|
||||
|
||||
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<CheckList> {
|
|||
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 &&
|
||||
|
|
|
|||
|
|
@ -83,6 +83,12 @@ class DBHelper {
|
|||
return db.insert("Item", item.toMap());
|
||||
}
|
||||
|
||||
Future<int> deleteItem(data.Check item) async {
|
||||
Database db = await database;
|
||||
|
||||
return db.delete("Item", where: 'id = ?', whereArgs: [item.id]);
|
||||
}
|
||||
|
||||
Future<int> updateItem(data.Check item) async {
|
||||
Database db = await database;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue