boxchecker/lib/box_checker.dart

122 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'add_form.dart';
import 'check_list.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.from(colorScheme: ColorScheme.dark()).copyWith(
canvasColor: Colors.blueGrey[900],
cardColor: Colors.grey[800],
scaffoldBackgroundColor: Colors.black12,
shadowColor: Colors.black38,
toggleableActiveColor: Colors.blue,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.blue,
),
),
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 = [];
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));
}
});
}
@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])))
.then((value) => _loadData(data.Page.values[_selectedPage]));
},
tooltip: 'Add List',
child: const Icon(Icons.add),
),
body: RefreshIndicator(
onRefresh: () => _loadData(data.Page.values[_selectedPage]),
child: ListView.builder(
itemCount: lists.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
CheckList(id: lists[index].id!)));
},
title: Text(lists[index].name),
subtitle: Text(lists[index].id.toString()),
),
);
})),
bottomNavigationBar: BottomNavigationBar(
elevation: 4,
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",
),
]));
}
}