Compare commits

..

No commits in common. "14c23baa7589ebf10d995e2bc14f631842e7fa9c" and "a7f4838ce910893c4724ee4ce60c1572bff7e17d" have entirely different histories.

2 changed files with 67 additions and 85 deletions

View File

@ -33,15 +33,6 @@ class _CheckList extends State<CheckList> {
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);
}
@ -61,77 +52,74 @@ class _CheckList extends State<CheckList> {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
appBar: AppBar(
title: Text((listData != null) ? listData!.name : 'Check List: $id'),
actions: (listData != null && listData!.isTemplate! && !_editable)
? [
IconButton(
onPressed: () => _toggleEditable(),
icon: const Icon(Icons.lock))
]
: (listData != null && listData!.isTemplate!)
? [
IconButton(
onPressed: () => _toggleEditable(),
icon: const Icon(Icons.lock_open))
]
: [],
),
body: RefreshIndicator(
onRefresh: () async {
_loadListData();
_loadList();
},
child: ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
return Card(
child: CheckboxListTile(
title: TextFormField(
enabled: (listData != null &&
(!listData!.isTemplate! || _editable)),
decoration: InputDecoration(border: InputBorder.none),
initialValue: list[index].text,
onChanged: (value) {
list[index].text = value;
_updateItem(list[index]);
},
),
controlAffinity: ListTileControlAffinity.leading,
value: list[index].value,
onChanged: (listData != null &&
(!listData!.isTemplate! || _editable))
? ((value) {
_updateItem(list[index]);
setState(() {
list[index].value = value!;
});
})
: null,
),
);
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
if (listData!.isTemplate! && !_editable) {
ScaffoldMessenger.of(context)
..clearSnackBars()
..showSnackBar(SnackBar(content: Text("Template is locked")));
return;
}
_addItem();
// TODO switch focus to new card
},
child: const Icon(Icons.check_box_outlined),
tooltip: "Add Item",
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text((listData != null) ? listData!.name : 'Check List: $id'),
actions: (listData != null && listData!.isTemplate! && !_editable)
? [
IconButton(
onPressed: () => _toggleEditable(),
icon: const Icon(Icons.lock))
]
: (listData != null && listData!.isTemplate!)
? [
IconButton(
onPressed: () => _toggleEditable(),
icon: const Icon(Icons.lock_open))
]
: [],
),
body: RefreshIndicator(
onRefresh: () async {
_loadListData();
_loadList();
},
child: ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
return Card(
child: CheckboxListTile(
title: TextFormField(
enabled: (listData != null &&
(!listData!.isTemplate! || _editable)),
decoration: InputDecoration(border: InputBorder.none),
initialValue: list[index].text,
onChanged: (value) {
list[index].text = value;
_updateItem(list[index]);
},
),
controlAffinity: ListTileControlAffinity.leading,
value: list[index].value,
onChanged:
(listData != null && (!listData!.isTemplate! || _editable))
? ((value) {
_updateItem(list[index]);
setState(() {
list[index].value = value!;
});
})
: null,
),
);
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
if (listData!.isTemplate! && !_editable) {
ScaffoldMessenger.of(context)
..clearSnackBars()
..showSnackBar(SnackBar(content: Text("Template is locked")));
return;
}
// TODO implment adding items to lists
},
child: const Icon(Icons.check_box_outlined),
tooltip: "Add Item",
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
);
}
}

View File

@ -77,12 +77,6 @@ class DBHelper {
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 {
Database db = await database;