Compare commits
No commits in common. "e793bc80a973c5a0e27620cb030b1a338f563e25" and "6bbb809a282276db4b36e8876b23c49beab60fc2" have entirely different histories.
e793bc80a9
...
6bbb809a28
|
|
@ -1,50 +1,15 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'data_util.dart' as data;
|
import 'data_util.dart' as data;
|
||||||
import 'db_helper.dart';
|
|
||||||
|
|
||||||
class AddForm extends StatefulWidget {
|
class AddForm extends StatelessWidget {
|
||||||
const AddForm({Key? key, required this.type}) : super(key: key);
|
AddForm({Key? key, required this.type}) : super(key: key);
|
||||||
final data.Page type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<StatefulWidget> createState() => _AddFormState(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AddFormState extends State<AddForm> {
|
|
||||||
_AddFormState(this.type);
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
final data.Page type;
|
final data.Page type;
|
||||||
int _templatChoice = -1;
|
int _templatChoice = -1;
|
||||||
List<data.List> templates = [];
|
|
||||||
|
|
||||||
final FocusNode _TemplateFocusNode = FocusNode();
|
final FocusNode _TemplateFocusNode = FocusNode();
|
||||||
|
|
||||||
void loadTemplates() async {
|
|
||||||
var rows = await DBHelper.dbHelper.getAllLists(data.Page.templates);
|
|
||||||
setState(() {
|
|
||||||
templates.clear();
|
|
||||||
for (var row in rows) {
|
|
||||||
var template = data.List.fromMap(row);
|
|
||||||
templates.add(template);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DropdownMenuItem<int>> generateDropdown() {
|
|
||||||
loadTemplates();
|
|
||||||
List<DropdownMenuItem<int>> items = [
|
|
||||||
DropdownMenuItem<int>(child: Text("None"), value: -1)
|
|
||||||
];
|
|
||||||
templates.asMap().forEach((index, value) {
|
|
||||||
items.add(DropdownMenuItem<int>(
|
|
||||||
child: Text(value.name),
|
|
||||||
value: index,
|
|
||||||
));
|
|
||||||
});
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -69,17 +34,21 @@ class _AddFormState extends State<AddForm> {
|
||||||
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
||||||
},
|
},
|
||||||
decoration: const InputDecoration(labelText: 'Label')),
|
decoration: const InputDecoration(labelText: 'Label')),
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField(
|
||||||
focusNode: _TemplateFocusNode,
|
focusNode: _TemplateFocusNode,
|
||||||
value: _templatChoice,
|
value: _templatChoice,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState() {
|
setState() {
|
||||||
_templatChoice = (value != null) ? value : -1;
|
_templatChoice = value as int;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
decoration:
|
decoration:
|
||||||
const InputDecoration(labelText: "Starting Template"),
|
const InputDecoration(labelText: "Starting Template"),
|
||||||
items: generateDropdown(),
|
items: const [
|
||||||
|
// TODO get templates from database
|
||||||
|
DropdownMenuItem<int>(child: Text("None"), value: -1),
|
||||||
|
DropdownMenuItem<int>(child: Text("1"), value: 0),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'add_form.dart';
|
import 'add_form.dart';
|
||||||
import 'db_helper.dart';
|
|
||||||
import 'data_util.dart' as data;
|
import 'data_util.dart' as data;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
@ -31,23 +30,6 @@ class MainListPage extends StatefulWidget {
|
||||||
|
|
||||||
class _MainListPageState extends State<MainListPage> {
|
class _MainListPageState extends State<MainListPage> {
|
||||||
int _selectedPage = data.Page.lists.index;
|
int _selectedPage = data.Page.lists.index;
|
||||||
List<data.List> lists = [data.List(100, "test")];
|
|
||||||
|
|
||||||
void _loadData(data.Page listType) async {
|
|
||||||
lists.clear();
|
|
||||||
var res = await DBHelper.dbHelper.getAllLists(listType);
|
|
||||||
setState(() {
|
|
||||||
for (var row in res) lists.add(data.List.fromMap(row));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
_loadData(data.Page.lists);
|
|
||||||
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -66,20 +48,14 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
tooltip: 'Add List',
|
tooltip: 'Add List',
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: ListView.builder(itemBuilder: (context, index) {
|
||||||
itemCount: lists.length,
|
return ListTile(); // TODO Implement tile rendering
|
||||||
itemBuilder: (context, index) {
|
}),
|
||||||
return ListTile(
|
|
||||||
title: Text(lists[index].name),
|
|
||||||
subtitle: Text(lists[index].id.toString()),
|
|
||||||
); // TODO Implement tile rendering
|
|
||||||
}),
|
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
currentIndex: _selectedPage,
|
currentIndex: _selectedPage,
|
||||||
onTap: (index) {
|
onTap: (index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedPage = index;
|
_selectedPage = index;
|
||||||
_loadData(data.Page.values[_selectedPage]);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
items: const [
|
items: const [
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ class List {
|
||||||
}
|
}
|
||||||
|
|
||||||
static List fromMap(Map<String, dynamic> map) {
|
static List fromMap(Map<String, dynamic> map) {
|
||||||
return List(map["id"], map["list_name"],
|
return List(map["id"], map["list_name"], isTemplate: map["is_template"]);
|
||||||
isTemplate: map["is_template"] == 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,7 +38,7 @@ class Check {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Check fromMap(Map<String, dynamic> map) {
|
static Check fromMap(Map<String, dynamic> map) {
|
||||||
return Check(map["id"], map["check_text"], map["value"] == 1,
|
return Check(map["id"], map["check_text"], map["value"],
|
||||||
listID: map["list_id"]);
|
listID: map["list_id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import "package:sqflite/sqflite.dart";
|
import "package:sqflite/sqflite.dart";
|
||||||
import "package:sqflite/sqlite_api.dart";
|
import "package:sqflite/sqlite_api.dart";
|
||||||
import "package:path/path.dart";
|
import "package:path/path.dart";
|
||||||
import 'data_util.dart' as data;
|
|
||||||
|
|
||||||
class DBHelper {
|
class DBHelper {
|
||||||
DBHelper._();
|
DBHelper._();
|
||||||
|
|
@ -22,16 +21,16 @@ class DBHelper {
|
||||||
onCreate: (Database db, int version) {
|
onCreate: (Database db, int version) {
|
||||||
db.execute("""
|
db.execute("""
|
||||||
CREATE TABLE List(
|
CREATE TABLE List(
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
list_name TEXT,
|
list_name TEXT
|
||||||
is_template int2
|
is_template int2
|
||||||
)
|
)
|
||||||
""");
|
""");
|
||||||
db.execute("""
|
db.execute("""
|
||||||
CREATE TABLE Item(
|
CREATE TABLE Check(
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
check_text TEXT,
|
check_text TEXT,
|
||||||
status int2,
|
value int2,
|
||||||
list_id INTEGER
|
list_id INTEGER
|
||||||
)
|
)
|
||||||
""");
|
""");
|
||||||
|
|
@ -42,20 +41,28 @@ class DBHelper {
|
||||||
(1, 'test template', 1)
|
(1, 'test template', 1)
|
||||||
""");
|
""");
|
||||||
db.execute("""
|
db.execute("""
|
||||||
INSERT INTO Item(id, check_text, status, list_id)
|
INSERT INTO CHECK(check_text, value, list_id)
|
||||||
VALUES
|
VALUES
|
||||||
(0, 'test item', 0, 0),
|
('test check', 1, 0),
|
||||||
(1, 'test item', 1, 0),
|
('test uncheck', 0, 0),
|
||||||
(2, 'test item', 0, 1),
|
('test check', 1, 1),
|
||||||
(3, 'test item', 1, 1)
|
('test uncheck', 0, 1)
|
||||||
""");
|
""");
|
||||||
}, version: 1);
|
}, version: 1);
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Map<String, dynamic>>> getAllLists(data.Page type) async {
|
Future<Map<String, dynamic>> getAllLists() async {
|
||||||
Database db = await database;
|
Database db = await database;
|
||||||
|
|
||||||
return db.query("List", where: "is_template = ?", whereArgs: [type.index]);
|
return db.query("List", where: "is_template = ?", whereArgs: ['0'])
|
||||||
|
as Map<String, dynamic>;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> getAllTemplates() async {
|
||||||
|
Database db = await database;
|
||||||
|
|
||||||
|
return db.query("List", where: "is_template = ?", whereArgs: ['1'])
|
||||||
|
as Map<String, dynamic>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue