From 14c23baa7589ebf10d995e2bc14f631842e7fa9c Mon Sep 17 00:00:00 2001 From: andrei Date: Wed, 3 Nov 2021 19:41:20 -0400 Subject: [PATCH] adding new items to lists --- lib/check_list.dart | 13 +++++++++++-- lib/db_helper.dart | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/check_list.dart b/lib/check_list.dart index 6a7cada..c8ec363 100644 --- a/lib/check_list.dart +++ b/lib/check_list.dart @@ -33,6 +33,15 @@ class _CheckList extends State { listData = (rows.isNotEmpty) ? data.List.fromMap(rows[0]) : null; } + void _addItem() async { + var item = data.Check("", false, listID: listData!.id!); + int id = await DBHelper.dbHelper.insertItem(item); + item.id = id; + setState(() { + list.add(item); + }); + } + void _updateItem(data.Check item) async { DBHelper.dbHelper.updateItem(item); } @@ -52,7 +61,6 @@ class _CheckList extends State { @override Widget build(BuildContext context) { - // TODO: implement build return GestureDetector( onTap: () => FocusScope.of(context).unfocus(), child: Scaffold( @@ -116,7 +124,8 @@ class _CheckList extends State { ..showSnackBar(SnackBar(content: Text("Template is locked"))); return; } - // TODO implment adding items to lists + _addItem(); + // TODO switch focus to new card }, child: const Icon(Icons.check_box_outlined), tooltip: "Add Item", diff --git a/lib/db_helper.dart b/lib/db_helper.dart index a1b12f8..33ec031 100644 --- a/lib/db_helper.dart +++ b/lib/db_helper.dart @@ -77,6 +77,12 @@ class DBHelper { return db.insert("List", l.toMap()); } + Future insertItem(data.Check item) async { + Database db = await database; + + return db.insert("Item", item.toMap()); + } + Future updateItem(data.Check item) async { Database db = await database;