Compare commits

..

No commits in common. "e793bc80a973c5a0e27620cb030b1a338f563e25" and "6bbb809a282276db4b36e8876b23c49beab60fc2" have entirely different histories.

4 changed files with 34 additions and 83 deletions

View File

@ -1,50 +1,15 @@
import 'package:flutter/material.dart';
import 'data_util.dart' as data;
import 'db_helper.dart';
class AddForm extends StatefulWidget {
const 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);
class AddForm extends StatelessWidget {
AddForm({Key? key, required this.type}) : super(key: key);
final _formKey = GlobalKey<FormState>();
final data.Page type;
int _templatChoice = -1;
List<data.List> templates = [];
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
Widget build(BuildContext context) {
return Scaffold(
@ -69,17 +34,21 @@ class _AddFormState extends State<AddForm> {
FocusScope.of(context).requestFocus(_TemplateFocusNode);
},
decoration: const InputDecoration(labelText: 'Label')),
DropdownButtonFormField<int>(
DropdownButtonFormField(
focusNode: _TemplateFocusNode,
value: _templatChoice,
onChanged: (value) {
setState() {
_templatChoice = (value != null) ? value : -1;
_templatChoice = value as int;
}
},
decoration:
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),
],
)
],
),

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'add_form.dart';
import 'db_helper.dart';
import 'data_util.dart' as data;
void main() {
@ -31,23 +30,6 @@ class MainListPage extends StatefulWidget {
class _MainListPageState extends State<MainListPage> {
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
Widget build(BuildContext context) {
return Scaffold(
@ -66,20 +48,14 @@ class _MainListPageState extends State<MainListPage> {
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()),
); // TODO Implement tile rendering
body: ListView.builder(itemBuilder: (context, index) {
return ListTile(); // TODO Implement tile rendering
}),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedPage,
onTap: (index) {
setState(() {
_selectedPage = index;
_loadData(data.Page.values[_selectedPage]);
});
},
items: const [

View File

@ -16,8 +16,7 @@ class List {
}
static List fromMap(Map<String, dynamic> map) {
return List(map["id"], map["list_name"],
isTemplate: map["is_template"] == 1);
return List(map["id"], map["list_name"], isTemplate: map["is_template"]);
}
}
@ -39,7 +38,7 @@ class Check {
}
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"]);
}
}

View File

@ -1,7 +1,6 @@
import "package:sqflite/sqflite.dart";
import "package:sqflite/sqlite_api.dart";
import "package:path/path.dart";
import 'data_util.dart' as data;
class DBHelper {
DBHelper._();
@ -22,16 +21,16 @@ class DBHelper {
onCreate: (Database db, int version) {
db.execute("""
CREATE TABLE List(
id INTEGER PRIMARY KEY,
list_name TEXT,
id INTEGER PRIMARY KEY AUTOINCREMENT,
list_name TEXT
is_template int2
)
""");
db.execute("""
CREATE TABLE Item(
id INTEGER PRIMARY KEY,
CREATE TABLE Check(
id INTEGER PRIMARY KEY AUTOINCREMENT,
check_text TEXT,
status int2,
value int2,
list_id INTEGER
)
""");
@ -42,20 +41,28 @@ class DBHelper {
(1, 'test template', 1)
""");
db.execute("""
INSERT INTO Item(id, check_text, status, list_id)
INSERT INTO CHECK(check_text, value, list_id)
VALUES
(0, 'test item', 0, 0),
(1, 'test item', 1, 0),
(2, 'test item', 0, 1),
(3, 'test item', 1, 1)
('test check', 1, 0),
('test uncheck', 0, 0),
('test check', 1, 1),
('test uncheck', 0, 1)
""");
}, version: 1);
return database;
}
Future<List<Map<String, dynamic>>> getAllLists(data.Page type) async {
Future<Map<String, dynamic>> getAllLists() async {
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>;
}
}