Compare commits
No commits in common. "a7f4838ce910893c4724ee4ce60c1572bff7e17d" and "236be3000f10aebb1afac8bc2441dd48c280f69f" have entirely different histories.
a7f4838ce9
...
236be3000f
|
|
@ -105,7 +105,6 @@ class _AddFormState extends State<AddForm> {
|
|||
_listLabel,
|
||||
isTemplate: type.index == 1,
|
||||
));
|
||||
// TODO implement template starting point
|
||||
Navigator.pop(context); // TODO replace route with checklist page
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'add_form.dart';
|
||||
import 'check_list.dart';
|
||||
import 'db_helper.dart';
|
||||
import 'data_util.dart' as data;
|
||||
|
||||
|
|
@ -16,11 +15,8 @@ class BoxChecker extends StatelessWidget {
|
|||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData.from(colorScheme: ColorScheme.dark()).copyWith(
|
||||
canvasColor: Colors.blueGrey[900],
|
||||
cardColor: Colors.grey[800],
|
||||
scaffoldBackgroundColor: Colors.black12,
|
||||
shadowColor: Colors.black38,
|
||||
toggleableActiveColor: Colors.blue,
|
||||
canvasColor: Colors.black,
|
||||
shadowColor: Colors.blueGrey,
|
||||
colorScheme: ColorScheme.fromSwatch(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
|
|
@ -84,18 +80,10 @@ class _MainListPageState extends State<MainListPage> {
|
|||
child: ListView.builder(
|
||||
itemCount: lists.length,
|
||||
itemBuilder: (context, index) {
|
||||
return 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()),
|
||||
),
|
||||
return ListTile(
|
||||
onTap: () {},
|
||||
title: Text(lists[index].name),
|
||||
subtitle: Text(lists[index].id.toString()),
|
||||
);
|
||||
})),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
|
|
|
|||
|
|
@ -1,125 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'data_util.dart' as data;
|
||||
import 'db_helper.dart';
|
||||
|
||||
class CheckList extends StatefulWidget {
|
||||
const CheckList({Key? key, required this.id}) : super(key: key);
|
||||
final int id;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CheckList(id);
|
||||
}
|
||||
|
||||
class _CheckList extends State<CheckList> {
|
||||
_CheckList(this.id);
|
||||
final int id;
|
||||
bool _editable = false;
|
||||
data.List? listData;
|
||||
List<data.Check> list = [];
|
||||
|
||||
void _loadList() async {
|
||||
var rows = await DBHelper.dbHelper.getList(id);
|
||||
|
||||
list.clear();
|
||||
setState(() {
|
||||
for (var row in rows) {
|
||||
list.add(data.Check.fromMap(row));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _loadListData() async {
|
||||
var rows = await DBHelper.dbHelper.getListData(id);
|
||||
listData = (rows.isNotEmpty) ? data.List.fromMap(rows[0]) : null;
|
||||
}
|
||||
|
||||
void _updateItem(data.Check item) async {
|
||||
DBHelper.dbHelper.updateItem(item);
|
||||
}
|
||||
|
||||
void _toggleEditable() {
|
||||
setState(() {
|
||||
_editable = !_editable;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_loadListData();
|
||||
_loadList();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,13 +33,13 @@ class Check {
|
|||
var map = Map<String, dynamic>();
|
||||
if (id != null) map["id"] = this.id;
|
||||
map["check_text"] = this.text;
|
||||
map["status"] = this.value ? 1 : 0;
|
||||
map["value"] = this.value as int;
|
||||
if (listID != null) map["list_id"] = this.listID! as int;
|
||||
return map;
|
||||
}
|
||||
|
||||
static Check fromMap(Map<String, dynamic> map) {
|
||||
return Check(map["check_text"], map["status"] == 1,
|
||||
return Check(map["check_text"], map["value"] == 1,
|
||||
id: map["id"], listID: map["list_id"]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,32 +59,9 @@ class DBHelper {
|
|||
return db.query("List", where: "is_template = ?", whereArgs: [type.index]);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getList(int id) async {
|
||||
Database db = await database;
|
||||
|
||||
return db.query("Item", where: "list_id = ?", whereArgs: [id]);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getListData(int id) async {
|
||||
Database db = await database;
|
||||
|
||||
return db.query("List", where: "id = ?", whereArgs: [id]);
|
||||
}
|
||||
|
||||
Future<int> insertList(data.List l) async {
|
||||
Database db = await database;
|
||||
|
||||
return db.insert("List", l.toMap());
|
||||
}
|
||||
|
||||
Future<int> updateItem(data.Check item) async {
|
||||
Database db = await database;
|
||||
|
||||
return db.update(
|
||||
"Item",
|
||||
item.toMap(),
|
||||
where: 'id = ?',
|
||||
whereArgs: [item.id],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue