171 lines
4.9 KiB
Dart
171 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:happy_camper_proto/checklist.dart';
|
|
import 'package:happy_camper_proto/listtemplates.dart';
|
|
import 'package:happy_camper_proto/preplist.dart';
|
|
import 'package:happy_camper_proto/templates_page.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
useMaterial3: true,
|
|
),
|
|
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
final String title;
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
late Widget page;
|
|
int _selectedPage = 0;
|
|
|
|
late List<Preplist> prepLists;
|
|
late List<ListTemplate> listTemplates;
|
|
|
|
void _showPage(int i) {
|
|
_selectedPage = i;
|
|
switch (_selectedPage) {
|
|
case 0:
|
|
page = PrepPage(prepLists: prepLists);
|
|
break;
|
|
case 1:
|
|
page = TemplatesPage(templates: listTemplates);
|
|
break;
|
|
default:
|
|
page = const Center(
|
|
child: Text("Hello World"),
|
|
);
|
|
}
|
|
setState(() {});
|
|
}
|
|
|
|
void _fabOnPress() async {
|
|
switch (_selectedPage) {
|
|
case 0:
|
|
var item = await showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
GlobalKey<FormState> formKey = GlobalKey();
|
|
TextEditingController inputController = TextEditingController();
|
|
|
|
return AlertDialog(
|
|
title: const Text("New List"),
|
|
content: Form(
|
|
key: formKey,
|
|
child: TextFormField(
|
|
controller: inputController,
|
|
decoration: const InputDecoration(hintText: "Name"),
|
|
)),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop(inputController.text);
|
|
},
|
|
child: const Text("Add"))
|
|
],
|
|
);
|
|
});
|
|
prepLists.add(Preplist(name: item, tasks: []));
|
|
break;
|
|
case 1:
|
|
var value = await showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
GlobalKey<FormState> formKey = GlobalKey();
|
|
TextEditingController inputController = TextEditingController();
|
|
|
|
return AlertDialog(
|
|
title: const Text("New Template"),
|
|
content: Form(
|
|
key: formKey,
|
|
child: TextFormField(
|
|
controller: inputController,
|
|
decoration: const InputDecoration(hintText: "Name"),
|
|
)),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop(inputController.text);
|
|
},
|
|
child: const Text("Add"))
|
|
],
|
|
);
|
|
});
|
|
listTemplates.add(ListTemplate(name: value));
|
|
break;
|
|
default:
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
content: Text("This page should not have a FAB"),
|
|
));
|
|
}
|
|
_showPage(_selectedPage);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
prepLists = Preplist.exampleData();
|
|
listTemplates = ListTemplate.exampleData();
|
|
page = PrepPage(prepLists: prepLists);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
title: Text(widget.title),
|
|
),
|
|
body: page,
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _selectedPage,
|
|
selectedItemColor: Theme.of(context).colorScheme.inversePrimary,
|
|
selectedFontSize:
|
|
(Theme.of(context).textTheme.labelLarge?.fontSize ?? 10) + 1,
|
|
onTap: _showPage,
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.check),
|
|
label: "Prep",
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.checklist),
|
|
label: "Templates",
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.route),
|
|
label: "Route",
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: (_selectedPage == 0 || _selectedPage == 1)
|
|
? FloatingActionButton(
|
|
mini: true,
|
|
onPressed: _fabOnPress,
|
|
child: const Icon(Icons.add),
|
|
)
|
|
: null,
|
|
floatingActionButtonLocation:
|
|
FloatingActionButtonLocation.miniCenterFloat,
|
|
);
|
|
}
|
|
}
|