Compare commits

...

2 Commits

Author SHA1 Message Date
andrei 236be3000f adding new lists 2021-11-03 14:52:39 -04:00
andrei 47402efd64 changed theme 2021-11-03 10:16:57 -04:00
4 changed files with 69 additions and 33 deletions

View File

@ -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,

View File

@ -14,7 +14,13 @@ class BoxChecker extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(brightness: Brightness.dark),
theme: ThemeData.from(colorScheme: ColorScheme.dark()).copyWith(
canvasColor: Colors.black,
shadowColor: Colors.blueGrey,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.blue,
),
),
themeMode: ThemeMode.dark,
home: const MainListPage(title: 'BoxChecker'),
);
@ -31,13 +37,15 @@ class MainListPage extends StatefulWidget {
class _MainListPageState extends State<MainListPage> {
int _selectedPage = data.Page.lists.index;
List<data.List> lists = [data.List(100, "test")];
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(() {
for (var row in res) lists.add(data.List.fromMap(row));
for (var row in res) {
lists.add(data.List.fromMap(row));
}
});
}
@ -58,23 +66,28 @@ class _MainListPageState extends State<MainListPage> {
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AddForm(type: data.Page.values[_selectedPage])));
}, // TODO Implement add button
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()),
); // TODO Implement tile rendering
}),
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,
onTap: (index) {
setState(() {

View File

@ -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"]);
}
}

View File

@ -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());
}
}