List descriptions

This commit is contained in:
andrei 2021-11-04 13:02:40 -04:00
parent 0aea396e99
commit b458393948
4 changed files with 26 additions and 10 deletions

View File

@ -17,6 +17,7 @@ class _AddFormState extends State<AddForm> {
final data.Page type; final data.Page type;
int _templatChoice = -1; int _templatChoice = -1;
String _listLabel = ""; String _listLabel = "";
String _listDesc = "";
List<data.List> templates = []; List<data.List> templates = [];
final FocusNode _TemplateFocusNode = FocusNode(); final FocusNode _TemplateFocusNode = FocusNode();
@ -81,6 +82,13 @@ class _AddFormState extends State<AddForm> {
} }
}, },
decoration: const InputDecoration(labelText: 'Label')), decoration: const InputDecoration(labelText: 'Label')),
TextFormField(
decoration:
const InputDecoration(labelText: 'Description(optional)'),
onChanged: (value) {
_listDesc = value;
},
),
DropdownButtonFormField<int>( DropdownButtonFormField<int>(
focusNode: _TemplateFocusNode, focusNode: _TemplateFocusNode,
value: _templatChoice, value: _templatChoice,
@ -103,7 +111,7 @@ class _AddFormState extends State<AddForm> {
data.List( data.List(
_listLabel, _listLabel,
isTemplate: type.index == 1, isTemplate: type.index == 1,
// TODO Add description to lists description: _listDesc,
), ),
); );
if (_templatChoice >= 0 && _templatChoice < templates.length) { if (_templatChoice >= 0 && _templatChoice < templates.length) {

View File

@ -146,7 +146,9 @@ class _MainListPageState extends State<MainListPage> {
CheckList(id: lists[index].id!))); CheckList(id: lists[index].id!)));
}, },
title: Text(lists[index].name), title: Text(lists[index].name),
subtitle: Text(lists[index].id.toString()), subtitle: Text((lists[index].description != null)
? lists[index].description!
: ""),
), ),
), ),
); );

View File

@ -1,23 +1,29 @@
enum Page { lists, templates } enum Page { lists, templates }
class List { class List {
List(this.name, {this.id, this.isTemplate}); List(this.name, {this.id, this.description, this.isTemplate});
int? id; int? id;
String name; String name;
String? description;
bool? isTemplate; bool? isTemplate;
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
var map = Map<String, dynamic>(); var map = Map<String, dynamic>();
if (id != null) map["id"] = this.id; if (id != null) map["id"] = this.id;
map["list_name"] = this.name; map["list_name"] = this.name;
if (description != null) map["list_desc"] = description;
if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0; if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0;
return map; return map;
} }
static List fromMap(Map<String, dynamic> map) { static List fromMap(Map<String, dynamic> map) {
return List(map["list_name"], return List(
id: map["id"], isTemplate: map["is_template"] == 1); map["list_name"],
id: map["id"],
description: map["list_desc"],
isTemplate: map["is_template"] == 1,
);
} }
} }

View File

@ -24,6 +24,7 @@ class DBHelper {
CREATE TABLE List( CREATE TABLE List(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
list_name TEXT, list_name TEXT,
list_desc TEXT,
is_template int2 is_template int2
) )
"""); """);
@ -36,10 +37,10 @@ class DBHelper {
) )
"""); """);
db.execute(""" db.execute("""
INSERT INTO List(id, list_name, is_template) INSERT INTO List(id, list_name, list_desc, is_template)
VALUES VALUES
(0, 'test list', 0), (0, 'test list', 'A list to test', 0),
(1, 'test template', 1) (1, 'test template', 'A template to test', 1)
"""); """);
db.execute(""" db.execute("""
INSERT INTO Item(id, check_text, status, list_id) INSERT INTO Item(id, check_text, status, list_id)
@ -49,7 +50,7 @@ class DBHelper {
(2, 'test item', 0, 1), (2, 'test item', 0, 1),
(3, 'test item', 1, 1) (3, 'test item', 1, 1)
"""); """);
}, version: 1); }, version: 2);
return database; return database;
} }
@ -86,7 +87,6 @@ class DBHelper {
Future<void> copyList(int oldID, int newID) async { Future<void> copyList(int oldID, int newID) async {
Database db = await database; Database db = await database;
print('$newID, $oldID');
var batch = db.batch(); var batch = db.batch();
db.execute(""" db.execute("""