Compare commits

..

2 Commits

Author SHA1 Message Date
andrei 14c23baa75 adding new items to lists 2021-11-03 19:41:20 -04:00
andrei 5bb8060a95 GestureDectector to clear keyboard 2021-11-03 18:55:51 -04:00
2 changed files with 84 additions and 66 deletions

View File

@ -33,6 +33,15 @@ class _CheckList extends State<CheckList> {
listData = (rows.isNotEmpty) ? data.List.fromMap(rows[0]) : null; 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 { void _updateItem(data.Check item) async {
DBHelper.dbHelper.updateItem(item); DBHelper.dbHelper.updateItem(item);
} }
@ -52,8 +61,9 @@ class _CheckList extends State<CheckList> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO: implement build return GestureDetector(
return Scaffold( onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text((listData != null) ? listData!.name : 'Check List: $id'), title: Text((listData != null) ? listData!.name : 'Check List: $id'),
actions: (listData != null && listData!.isTemplate! && !_editable) actions: (listData != null && listData!.isTemplate! && !_editable)
@ -92,8 +102,8 @@ class _CheckList extends State<CheckList> {
), ),
controlAffinity: ListTileControlAffinity.leading, controlAffinity: ListTileControlAffinity.leading,
value: list[index].value, value: list[index].value,
onChanged: onChanged: (listData != null &&
(listData != null && (!listData!.isTemplate! || _editable)) (!listData!.isTemplate! || _editable))
? ((value) { ? ((value) {
_updateItem(list[index]); _updateItem(list[index]);
setState(() { setState(() {
@ -114,12 +124,14 @@ class _CheckList extends State<CheckList> {
..showSnackBar(SnackBar(content: Text("Template is locked"))); ..showSnackBar(SnackBar(content: Text("Template is locked")));
return; return;
} }
// TODO implment adding items to lists _addItem();
// TODO switch focus to new card
}, },
child: const Icon(Icons.check_box_outlined), child: const Icon(Icons.check_box_outlined),
tooltip: "Add Item", tooltip: "Add Item",
), ),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
),
); );
} }
} }

View File

@ -77,6 +77,12 @@ class DBHelper {
return db.insert("List", l.toMap()); return db.insert("List", l.toMap());
} }
Future<int> insertItem(data.Check item) async {
Database db = await database;
return db.insert("Item", item.toMap());
}
Future<int> updateItem(data.Check item) async { Future<int> updateItem(data.Check item) async {
Database db = await database; Database db = await database;