Compare commits
No commits in common. "236be3000f10aebb1afac8bc2441dd48c280f69f" and "e793bc80a973c5a0e27620cb030b1a338f563e25" have entirely different histories.
236be3000f
...
e793bc80a9
|
|
@ -16,7 +16,6 @@ class _AddFormState extends State<AddForm> {
|
||||||
|
|
||||||
final data.Page type;
|
final data.Page type;
|
||||||
int _templatChoice = -1;
|
int _templatChoice = -1;
|
||||||
String _listLabel = "";
|
|
||||||
List<data.List> templates = [];
|
List<data.List> templates = [];
|
||||||
|
|
||||||
final FocusNode _TemplateFocusNode = FocusNode();
|
final FocusNode _TemplateFocusNode = FocusNode();
|
||||||
|
|
@ -66,19 +65,8 @@ class _AddFormState extends State<AddForm> {
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
onChanged: (value) {
|
|
||||||
_listLabel = value;
|
|
||||||
},
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return 'Label is required';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
onFieldSubmitted: (value) {
|
onFieldSubmitted: (value) {
|
||||||
if (_formKey.currentState!.validate()) {
|
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
||||||
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
decoration: const InputDecoration(labelText: 'Label')),
|
decoration: const InputDecoration(labelText: 'Label')),
|
||||||
DropdownButtonFormField<int>(
|
DropdownButtonFormField<int>(
|
||||||
|
|
@ -99,14 +87,9 @@ class _AddFormState extends State<AddForm> {
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: Icon(Icons.save_alt),
|
child: Icon(Icons.save_alt),
|
||||||
onPressed: () async {
|
onPressed: () {
|
||||||
if (_formKey.currentState!.validate()) {
|
// TODO implement adding list to database
|
||||||
DBHelper.dbHelper.insertList(data.List(
|
Navigator.pop(context); // TODO replace route with checklist page
|
||||||
_listLabel,
|
|
||||||
isTemplate: type.index == 1,
|
|
||||||
));
|
|
||||||
Navigator.pop(context); // TODO replace route with checklist page
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,7 @@ class BoxChecker extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Flutter Demo',
|
||||||
theme: ThemeData.from(colorScheme: ColorScheme.dark()).copyWith(
|
theme: ThemeData(brightness: Brightness.dark),
|
||||||
canvasColor: Colors.black,
|
|
||||||
shadowColor: Colors.blueGrey,
|
|
||||||
colorScheme: ColorScheme.fromSwatch(
|
|
||||||
primarySwatch: Colors.blue,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
themeMode: ThemeMode.dark,
|
themeMode: ThemeMode.dark,
|
||||||
home: const MainListPage(title: 'BoxChecker'),
|
home: const MainListPage(title: 'BoxChecker'),
|
||||||
);
|
);
|
||||||
|
|
@ -37,15 +31,13 @@ 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 = [];
|
List<data.List> lists = [data.List(100, "test")];
|
||||||
|
|
||||||
Future<void> _loadData(data.Page listType) async {
|
void _loadData(data.Page listType) async {
|
||||||
lists.clear();
|
lists.clear();
|
||||||
var res = await DBHelper.dbHelper.getAllLists(listType);
|
var res = await DBHelper.dbHelper.getAllLists(listType);
|
||||||
setState(() {
|
setState(() {
|
||||||
for (var row in res) {
|
for (var row in res) lists.add(data.List.fromMap(row));
|
||||||
lists.add(data.List.fromMap(row));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,28 +58,23 @@ class _MainListPageState extends State<MainListPage> {
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
AddForm(type: data.Page.values[_selectedPage])))
|
AddForm(type: data.Page.values[_selectedPage])));
|
||||||
.then((value) => _loadData(data.Page.values[_selectedPage]));
|
}, // TODO Implement add button
|
||||||
},
|
|
||||||
tooltip: 'Add List',
|
tooltip: 'Add List',
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: ListView.builder(
|
||||||
onRefresh: () => _loadData(data.Page.values[_selectedPage]),
|
itemCount: lists.length,
|
||||||
child: ListView.builder(
|
itemBuilder: (context, index) {
|
||||||
itemCount: lists.length,
|
return ListTile(
|
||||||
itemBuilder: (context, index) {
|
title: Text(lists[index].name),
|
||||||
return ListTile(
|
subtitle: Text(lists[index].id.toString()),
|
||||||
onTap: () {},
|
); // TODO Implement tile rendering
|
||||||
title: Text(lists[index].name),
|
}),
|
||||||
subtitle: Text(lists[index].id.toString()),
|
|
||||||
);
|
|
||||||
})),
|
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
elevation: 4,
|
|
||||||
currentIndex: _selectedPage,
|
currentIndex: _selectedPage,
|
||||||
onTap: (index) {
|
onTap: (index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,45 @@
|
||||||
enum Page { lists, templates }
|
enum Page { lists, templates }
|
||||||
|
|
||||||
class List {
|
class List {
|
||||||
List(this.name, {this.id, this.isTemplate});
|
List(this.id, this.name, {this.isTemplate});
|
||||||
|
|
||||||
int? id;
|
int id;
|
||||||
String name;
|
String name;
|
||||||
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;
|
map["id"] = this.id;
|
||||||
map["list_name"] = this.name;
|
map["list_name"] = this.name;
|
||||||
if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0;
|
if (isTemplate != null) map["is_template"] = this.isTemplate as int;
|
||||||
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(map["id"], map["list_name"],
|
||||||
id: map["id"], isTemplate: map["is_template"] == 1);
|
isTemplate: map["is_template"] == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Check {
|
class Check {
|
||||||
Check(this.text, this.value, {this.id, this.listID});
|
Check(this.id, this.text, this.value, {this.listID});
|
||||||
|
|
||||||
int? id;
|
int id;
|
||||||
String text;
|
String text;
|
||||||
bool value;
|
bool value;
|
||||||
int? listID;
|
int? listID;
|
||||||
|
|
||||||
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;
|
map["id"] = this.id;
|
||||||
map["check_text"] = this.text;
|
map["check_text"] = this.text;
|
||||||
map["value"] = this.value as int;
|
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;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Check fromMap(Map<String, dynamic> map) {
|
static Check fromMap(Map<String, dynamic> map) {
|
||||||
return Check(map["check_text"], map["value"] == 1,
|
return Check(map["id"], map["check_text"], map["value"] == 1,
|
||||||
id: map["id"], listID: map["list_id"]);
|
listID: map["list_id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,4 @@ class DBHelper {
|
||||||
|
|
||||||
return db.query("List", where: "is_template = ?", whereArgs: [type.index]);
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue