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;
|
||||
int _templatChoice = -1;
|
||||
String _listLabel = "";
|
||||
List<data.List> templates = [];
|
||||
|
||||
final FocusNode _TemplateFocusNode = FocusNode();
|
||||
|
|
@ -66,19 +65,8 @@ 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) {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
FocusScope.of(context).requestFocus(_TemplateFocusNode);
|
||||
}
|
||||
},
|
||||
decoration: const InputDecoration(labelText: 'Label')),
|
||||
DropdownButtonFormField<int>(
|
||||
|
|
@ -99,14 +87,9 @@ class _AddFormState extends State<AddForm> {
|
|||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.save_alt),
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
DBHelper.dbHelper.insertList(data.List(
|
||||
_listLabel,
|
||||
isTemplate: type.index == 1,
|
||||
));
|
||||
onPressed: () {
|
||||
// TODO implement adding list to database
|
||||
Navigator.pop(context); // TODO replace route with checklist page
|
||||
}
|
||||
},
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
|
|
|
|||
|
|
@ -14,13 +14,7 @@ class BoxChecker extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData.from(colorScheme: ColorScheme.dark()).copyWith(
|
||||
canvasColor: Colors.black,
|
||||
shadowColor: Colors.blueGrey,
|
||||
colorScheme: ColorScheme.fromSwatch(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
),
|
||||
theme: ThemeData(brightness: Brightness.dark),
|
||||
themeMode: ThemeMode.dark,
|
||||
home: const MainListPage(title: 'BoxChecker'),
|
||||
);
|
||||
|
|
@ -37,15 +31,13 @@ class MainListPage extends StatefulWidget {
|
|||
|
||||
class _MainListPageState extends State<MainListPage> {
|
||||
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();
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -69,25 +61,20 @@ class _MainListPageState extends State<MainListPage> {
|
|||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
AddForm(type: data.Page.values[_selectedPage])))
|
||||
.then((value) => _loadData(data.Page.values[_selectedPage]));
|
||||
},
|
||||
AddForm(type: data.Page.values[_selectedPage])));
|
||||
}, // TODO Implement add button
|
||||
tooltip: 'Add List',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _loadData(data.Page.values[_selectedPage]),
|
||||
child: ListView.builder(
|
||||
body: ListView.builder(
|
||||
itemCount: lists.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
onTap: () {},
|
||||
title: Text(lists[index].name),
|
||||
subtitle: Text(lists[index].id.toString()),
|
||||
);
|
||||
})),
|
||||
); // TODO Implement tile rendering
|
||||
}),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
elevation: 4,
|
||||
currentIndex: _selectedPage,
|
||||
onTap: (index) {
|
||||
setState(() {
|
||||
|
|
|
|||
|
|
@ -1,45 +1,45 @@
|
|||
enum Page { lists, templates }
|
||||
|
||||
class List {
|
||||
List(this.name, {this.id, this.isTemplate});
|
||||
List(this.id, this.name, {this.isTemplate});
|
||||
|
||||
int? id;
|
||||
int id;
|
||||
String name;
|
||||
bool? isTemplate;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
var map = Map<String, dynamic>();
|
||||
if (id != null) map["id"] = this.id;
|
||||
map["id"] = this.id;
|
||||
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;
|
||||
}
|
||||
|
||||
static List fromMap(Map<String, dynamic> map) {
|
||||
return List(map["list_name"],
|
||||
id: map["id"], isTemplate: map["is_template"] == 1);
|
||||
return List(map["id"], map["list_name"],
|
||||
isTemplate: map["is_template"] == 1);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
bool value;
|
||||
int? listID;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
var map = Map<String, dynamic>();
|
||||
if (id != null) map["id"] = this.id;
|
||||
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["check_text"], map["value"] == 1,
|
||||
id: map["id"], listID: map["list_id"]);
|
||||
return Check(map["id"], map["check_text"], map["value"] == 1,
|
||||
listID: map["list_id"]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,4 @@ 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue