adding new lists
This commit is contained in:
parent
47402efd64
commit
236be3000f
|
|
@ -16,6 +16,7 @@ class _AddFormState extends State<AddForm> {
|
|||
|
||||
final data.Page type;
|
||||
int _templatChoice = -1;
|
||||
String _listLabel = "";
|
||||
List<data.List> templates = [];
|
||||
|
||||
final FocusNode _TemplateFocusNode = FocusNode();
|
||||
|
|
@ -65,8 +66,19 @@ class _AddFormState extends State<AddForm> {
|
|||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
onChanged: (value) {
|
||||
_listLabel = value;
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Label is required';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onFieldSubmitted: (value) {
|
||||
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
||||
if (_formKey.currentState!.validate()) {
|
||||
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
||||
}
|
||||
},
|
||||
decoration: const InputDecoration(labelText: 'Label')),
|
||||
DropdownButtonFormField<int>(
|
||||
|
|
@ -87,9 +99,14 @@ class _AddFormState extends State<AddForm> {
|
|||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.save_alt),
|
||||
onPressed: () {
|
||||
// TODO implement adding list to database
|
||||
Navigator.pop(context); // TODO replace route with checklist page
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
DBHelper.dbHelper.insertList(data.List(
|
||||
_listLabel,
|
||||
isTemplate: type.index == 1,
|
||||
));
|
||||
Navigator.pop(context); // TODO replace route with checklist page
|
||||
}
|
||||
},
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class _MainListPageState extends State<MainListPage> {
|
|||
int _selectedPage = data.Page.lists.index;
|
||||
List<data.List> lists = [];
|
||||
|
||||
void _loadData(data.Page listType) async {
|
||||
Future<void> _loadData(data.Page listType) async {
|
||||
lists.clear();
|
||||
var res = await DBHelper.dbHelper.getAllLists(listType);
|
||||
setState(() {
|
||||
|
|
@ -66,22 +66,26 @@ class _MainListPageState extends State<MainListPage> {
|
|||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
AddForm(type: data.Page.values[_selectedPage])));
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
AddForm(type: data.Page.values[_selectedPage])))
|
||||
.then((value) => _loadData(data.Page.values[_selectedPage]));
|
||||
},
|
||||
tooltip: 'Add List',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: lists.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(lists[index].name),
|
||||
subtitle: Text(lists[index].id.toString()),
|
||||
);
|
||||
}),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _loadData(data.Page.values[_selectedPage]),
|
||||
child: ListView.builder(
|
||||
itemCount: lists.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
onTap: () {},
|
||||
title: Text(lists[index].name),
|
||||
subtitle: Text(lists[index].id.toString()),
|
||||
);
|
||||
})),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
elevation: 4,
|
||||
currentIndex: _selectedPage,
|
||||
|
|
|
|||
|
|
@ -1,45 +1,45 @@
|
|||
enum Page { lists, templates }
|
||||
|
||||
class List {
|
||||
List(this.id, this.name, {this.isTemplate});
|
||||
List(this.name, {this.id, this.isTemplate});
|
||||
|
||||
int id;
|
||||
int? id;
|
||||
String name;
|
||||
bool? isTemplate;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
var map = Map<String, dynamic>();
|
||||
map["id"] = this.id;
|
||||
if (id != null) map["id"] = this.id;
|
||||
map["list_name"] = this.name;
|
||||
if (isTemplate != null) map["is_template"] = this.isTemplate as int;
|
||||
if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0;
|
||||
return map;
|
||||
}
|
||||
|
||||
static List fromMap(Map<String, dynamic> map) {
|
||||
return List(map["id"], map["list_name"],
|
||||
isTemplate: map["is_template"] == 1);
|
||||
return List(map["list_name"],
|
||||
id: map["id"], isTemplate: map["is_template"] == 1);
|
||||
}
|
||||
}
|
||||
|
||||
class Check {
|
||||
Check(this.id, this.text, this.value, {this.listID});
|
||||
Check(this.text, this.value, {this.id, this.listID});
|
||||
|
||||
int id;
|
||||
int? id;
|
||||
String text;
|
||||
bool value;
|
||||
int? listID;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
var map = Map<String, dynamic>();
|
||||
map["id"] = this.id;
|
||||
if (id != null) map["id"] = this.id;
|
||||
map["check_text"] = this.text;
|
||||
map["value"] = this.value as int;
|
||||
if (listID != null) map["list_id"] = this.listID as int;
|
||||
if (listID != null) map["list_id"] = this.listID! as int;
|
||||
return map;
|
||||
}
|
||||
|
||||
static Check fromMap(Map<String, dynamic> map) {
|
||||
return Check(map["id"], map["check_text"], map["value"] == 1,
|
||||
listID: map["list_id"]);
|
||||
return Check(map["check_text"], map["value"] == 1,
|
||||
id: map["id"], listID: map["list_id"]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,4 +58,10 @@ class DBHelper {
|
|||
|
||||
return db.query("List", where: "is_template = ?", whereArgs: [type.index]);
|
||||
}
|
||||
|
||||
Future<int> insertList(data.List l) async {
|
||||
Database db = await database;
|
||||
|
||||
return db.insert("List", l.toMap());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue