From b4583939483795482229165412f34889cf3f5780 Mon Sep 17 00:00:00 2001 From: andrei Date: Thu, 4 Nov 2021 13:02:40 -0400 Subject: [PATCH] List descriptions --- lib/add_form.dart | 10 +++++++++- lib/box_checker.dart | 4 +++- lib/data_util.dart | 12 +++++++++--- lib/db_helper.dart | 10 +++++----- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/add_form.dart b/lib/add_form.dart index eeaaeb7..4c7c847 100644 --- a/lib/add_form.dart +++ b/lib/add_form.dart @@ -17,6 +17,7 @@ class _AddFormState extends State { final data.Page type; int _templatChoice = -1; String _listLabel = ""; + String _listDesc = ""; List templates = []; final FocusNode _TemplateFocusNode = FocusNode(); @@ -81,6 +82,13 @@ class _AddFormState extends State { } }, decoration: const InputDecoration(labelText: 'Label')), + TextFormField( + decoration: + const InputDecoration(labelText: 'Description(optional)'), + onChanged: (value) { + _listDesc = value; + }, + ), DropdownButtonFormField( focusNode: _TemplateFocusNode, value: _templatChoice, @@ -103,7 +111,7 @@ class _AddFormState extends State { data.List( _listLabel, isTemplate: type.index == 1, - // TODO Add description to lists + description: _listDesc, ), ); if (_templatChoice >= 0 && _templatChoice < templates.length) { diff --git a/lib/box_checker.dart b/lib/box_checker.dart index af01e2f..deb9814 100644 --- a/lib/box_checker.dart +++ b/lib/box_checker.dart @@ -146,7 +146,9 @@ class _MainListPageState extends State { CheckList(id: lists[index].id!))); }, title: Text(lists[index].name), - subtitle: Text(lists[index].id.toString()), + subtitle: Text((lists[index].description != null) + ? lists[index].description! + : ""), ), ), ); diff --git a/lib/data_util.dart b/lib/data_util.dart index 98a6a1e..181aeec 100644 --- a/lib/data_util.dart +++ b/lib/data_util.dart @@ -1,23 +1,29 @@ enum Page { lists, templates } class List { - List(this.name, {this.id, this.isTemplate}); + List(this.name, {this.id, this.description, this.isTemplate}); int? id; String name; + String? description; bool? isTemplate; Map toMap() { var map = Map(); if (id != null) map["id"] = this.id; map["list_name"] = this.name; + if (description != null) map["list_desc"] = description; if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0; return map; } static List fromMap(Map map) { - return List(map["list_name"], - id: map["id"], isTemplate: map["is_template"] == 1); + return List( + map["list_name"], + id: map["id"], + description: map["list_desc"], + isTemplate: map["is_template"] == 1, + ); } } diff --git a/lib/db_helper.dart b/lib/db_helper.dart index e53cf57..9dfeb18 100644 --- a/lib/db_helper.dart +++ b/lib/db_helper.dart @@ -24,6 +24,7 @@ class DBHelper { CREATE TABLE List( id INTEGER PRIMARY KEY, list_name TEXT, + list_desc TEXT, is_template int2 ) """); @@ -36,10 +37,10 @@ class DBHelper { ) """); db.execute(""" - INSERT INTO List(id, list_name, is_template) + INSERT INTO List(id, list_name, list_desc, is_template) VALUES - (0, 'test list', 0), - (1, 'test template', 1) + (0, 'test list', 'A list to test', 0), + (1, 'test template', 'A template to test', 1) """); db.execute(""" INSERT INTO Item(id, check_text, status, list_id) @@ -49,7 +50,7 @@ class DBHelper { (2, 'test item', 0, 1), (3, 'test item', 1, 1) """); - }, version: 1); + }, version: 2); return database; } @@ -86,7 +87,6 @@ class DBHelper { Future copyList(int oldID, int newID) async { Database db = await database; - print('$newID, $oldID'); var batch = db.batch(); db.execute("""