deletable lists
This commit is contained in:
parent
7b1f6860e3
commit
02fa1f75b3
|
|
@ -53,6 +53,10 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _removeList(data.List list) async {
|
||||||
|
DBHelper.dbHelper.deleteList(list);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_loadData(data.Page.lists);
|
_loadData(data.Page.lists);
|
||||||
|
|
@ -84,17 +88,66 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: lists.length,
|
itemCount: lists.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return Card(
|
return Dismissible(
|
||||||
child: ListTile(
|
direction: DismissDirection.startToEnd,
|
||||||
onTap: () {
|
key: Key(lists[index].id.toString()),
|
||||||
Navigator.push(
|
background: Card(
|
||||||
context,
|
color: Colors.red,
|
||||||
MaterialPageRoute(
|
child: Row(
|
||||||
builder: (context) =>
|
children: const [
|
||||||
CheckList(id: lists[index].id!)));
|
Padding(
|
||||||
},
|
padding: EdgeInsets.all(10),
|
||||||
title: Text(lists[index].name),
|
child: Icon(Icons.delete),
|
||||||
subtitle: Text(lists[index].id.toString()),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
confirmDismiss: (direction) async {
|
||||||
|
if (direction != DismissDirection.startToEnd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Are you sure?'),
|
||||||
|
content: const Text(
|
||||||
|
'You are about to delete this permently'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () =>
|
||||||
|
Navigator.pop(context, false),
|
||||||
|
child: const Text('Cancel')),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () =>
|
||||||
|
Navigator.pop(context, true),
|
||||||
|
child: const Text('OK')),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}).then((value) {
|
||||||
|
if (value) {
|
||||||
|
setState(() {
|
||||||
|
_removeList(lists[index]);
|
||||||
|
lists.removeAt(index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Card(
|
||||||
|
child: ListTile(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
CheckList(id: lists[index].id!)));
|
||||||
|
},
|
||||||
|
title: Text(lists[index].name),
|
||||||
|
subtitle: Text(lists[index].id.toString()),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
})),
|
})),
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,12 @@ class DBHelper {
|
||||||
return db.insert("List", l.toMap());
|
return db.insert("List", l.toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> deleteList(data.List l) async {
|
||||||
|
Database db = await database;
|
||||||
|
|
||||||
|
return db.delete("List", where: 'id = ?', whereArgs: [l.id]);
|
||||||
|
}
|
||||||
|
|
||||||
Future<int> insertItem(data.Check item) async {
|
Future<int> insertItem(data.Check item) async {
|
||||||
Database db = await database;
|
Database db = await database;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue