97 lines
2.8 KiB
Dart
97 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'add_form.dart';
|
|
import 'db_helper.dart';
|
|
import 'data_util.dart' as data;
|
|
|
|
void main() {
|
|
runApp(const BoxChecker());
|
|
}
|
|
|
|
class BoxChecker extends StatelessWidget {
|
|
const BoxChecker({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(brightness: Brightness.dark),
|
|
themeMode: ThemeMode.dark,
|
|
home: const MainListPage(title: 'BoxChecker'),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MainListPage extends StatefulWidget {
|
|
const MainListPage({Key? key, required this.title}) : super(key: key);
|
|
final String title;
|
|
|
|
@override
|
|
State<MainListPage> createState() => _MainListPageState();
|
|
}
|
|
|
|
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(
|
|
appBar: AppBar(
|
|
title: Text(widget.title),
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
AddForm(type: data.Page.values[_selectedPage])));
|
|
}, // TODO Implement add button
|
|
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
|
|
}),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _selectedPage,
|
|
onTap: (index) {
|
|
setState(() {
|
|
_selectedPage = index;
|
|
_loadData(data.Page.values[_selectedPage]);
|
|
});
|
|
},
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.checklist),
|
|
label: "Lists",
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.folder_open),
|
|
label: "Templates",
|
|
),
|
|
]));
|
|
}
|
|
}
|