Compare commits
No commits in common. "9bc03102059890e22e2f25f3d832a0823f106e8e" and "7b1f6860e32d735b6d54ab2ec569ebd53b8274b8" have entirely different histories.
9bc0310205
...
7b1f6860e3
|
|
@ -84,9 +84,11 @@ class _AddFormState extends State<AddForm> {
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField<int>(
|
||||||
focusNode: _TemplateFocusNode,
|
focusNode: _TemplateFocusNode,
|
||||||
value: _templatChoice,
|
value: _templatChoice,
|
||||||
onChanged: (value) => setState(() {
|
onChanged: (value) {
|
||||||
_templatChoice = value!;
|
setState() {
|
||||||
}),
|
_templatChoice = (value != null) ? value : -1;
|
||||||
|
}
|
||||||
|
},
|
||||||
decoration:
|
decoration:
|
||||||
const InputDecoration(labelText: "Starting Template"),
|
const InputDecoration(labelText: "Starting Template"),
|
||||||
items: generateDropdown(),
|
items: generateDropdown(),
|
||||||
|
|
@ -99,16 +101,11 @@ class _AddFormState extends State<AddForm> {
|
||||||
child: Icon(Icons.save_alt),
|
child: Icon(Icons.save_alt),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
int id = await DBHelper.dbHelper.insertList(
|
DBHelper.dbHelper.insertList(data.List(
|
||||||
data.List(
|
_listLabel,
|
||||||
_listLabel,
|
isTemplate: type.index == 1,
|
||||||
isTemplate: type.index == 1,
|
));
|
||||||
// TODO Add description to lists
|
// TODO implement template starting point
|
||||||
),
|
|
||||||
);
|
|
||||||
if (_templatChoice >= 0 && _templatChoice < templates.length) {
|
|
||||||
DBHelper.dbHelper.copyList(templates[_templatChoice].id!, id);
|
|
||||||
}
|
|
||||||
Navigator.pop(context); // TODO replace route with checklist page
|
Navigator.pop(context); // TODO replace route with checklist page
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,6 @@ 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);
|
||||||
|
|
@ -88,66 +84,17 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: lists.length,
|
itemCount: lists.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return Dismissible(
|
return Card(
|
||||||
direction: DismissDirection.startToEnd,
|
child: ListTile(
|
||||||
key: Key(lists[index].id.toString()),
|
onTap: () {
|
||||||
background: Card(
|
Navigator.push(
|
||||||
color: Colors.red,
|
context,
|
||||||
child: Row(
|
MaterialPageRoute(
|
||||||
children: const [
|
builder: (context) =>
|
||||||
Padding(
|
CheckList(id: lists[index].id!)));
|
||||||
padding: EdgeInsets.all(10),
|
},
|
||||||
child: Icon(Icons.delete),
|
title: Text(lists[index].name),
|
||||||
),
|
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,35 +77,6 @@ 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;
|
|
||||||
|
|
||||||
db.delete("Item", where: 'list_id = ?', whereArgs: [l.id]);
|
|
||||||
return db.delete("List", where: 'id = ?', whereArgs: [l.id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> copyList(int oldID, int newID) async {
|
|
||||||
Database db = await database;
|
|
||||||
print('$newID, $oldID');
|
|
||||||
|
|
||||||
var batch = db.batch();
|
|
||||||
db.execute("""
|
|
||||||
CREATE TEMPORARY TABLE list_copy AS
|
|
||||||
SELECT check_text, status, list_id
|
|
||||||
FROM Item
|
|
||||||
WHERE list_id = ?
|
|
||||||
""", [oldID]);
|
|
||||||
db.update("list_copy", {'list_id': newID});
|
|
||||||
db.rawInsert("""
|
|
||||||
INSERT INTO Item(check_text, status, list_id)
|
|
||||||
SELECT * FROM list_copy
|
|
||||||
""");
|
|
||||||
db.execute("""
|
|
||||||
DROP TABLE list_copy
|
|
||||||
""");
|
|
||||||
batch.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
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