fmassive/lib/home_page.dart

106 lines
2.8 KiB
Dart
Raw Normal View History

2023-04-07 11:50:02 +12:00
import 'package:flutter/material.dart';
2023-04-11 11:41:10 +12:00
import 'package:fmassive/best_page.dart';
import 'package:fmassive/plans_page.dart';
2023-04-17 11:03:36 +12:00
import 'package:fmassive/set_list.dart';
2023-04-11 11:41:10 +12:00
import 'package:fmassive/settings_page.dart';
import 'package:fmassive/timer_page.dart';
import 'package:fmassive/workouts_page.dart';
2023-04-07 11:50:02 +12:00
2023-04-11 11:41:10 +12:00
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
2023-04-17 11:03:36 +12:00
createState() => _HomePage();
2023-04-11 11:41:10 +12:00
}
2023-04-17 11:03:36 +12:00
class _HomePage extends State<HomePage> {
2023-04-11 11:41:10 +12:00
bool showSearch = false;
int selected = 0;
String search = '';
final focusNode = FocusNode();
2023-04-07 11:50:02 +12:00
2023-04-07 15:56:17 +12:00
final List<Map<String, dynamic>> routes = [
2023-04-07 11:50:02 +12:00
{'title': 'Home', 'icon': Icons.home},
{'title': 'Plans', 'icon': Icons.calendar_today},
{'title': 'Best', 'icon': Icons.star},
{'title': 'Workouts', 'icon': Icons.fitness_center},
{'title': 'Timer', 'icon': Icons.timer},
{'title': 'Settings', 'icon': Icons.settings},
];
2023-04-11 11:41:10 +12:00
void toggleSearch() {
setState(() {
2023-04-11 13:14:26 +12:00
if (showSearch) search = '';
2023-04-11 11:41:10 +12:00
showSearch = !showSearch;
});
focusNode.requestFocus();
}
Widget getBody() {
switch (routes[selected]['title']) {
case 'Settings':
2023-04-13 17:23:26 +12:00
return SettingsPage(search: search);
2023-04-11 11:41:10 +12:00
case 'Timer':
return const TimerPage();
case 'Workouts':
return const WorkoutsPage();
case 'Best':
return const BestPage();
case 'Plans':
2023-04-13 18:58:26 +12:00
return PlansPage(search: search);
2023-04-11 11:41:10 +12:00
default:
2023-04-15 17:03:30 +12:00
return SetList(search: search);
2023-04-11 11:41:10 +12:00
}
}
2023-04-07 11:50:02 +12:00
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
2023-04-07 11:50:02 +12:00
drawer: Drawer(
child: ListView.builder(
2023-04-07 15:56:17 +12:00
itemCount: routes.length,
2023-04-07 11:50:02 +12:00
itemBuilder: (context, index) {
return ListTile(
2023-04-11 11:41:10 +12:00
selected: selected == index,
2023-04-07 15:56:17 +12:00
leading: Icon(routes[index]['icon']),
title: Text(routes[index]['title']),
2023-04-07 11:50:02 +12:00
onTap: () {
2023-04-11 11:41:10 +12:00
setState(() {
selected = index;
});
2023-04-07 11:50:02 +12:00
Navigator.pop(context);
},
);
},
),
),
2023-04-11 11:41:10 +12:00
appBar: AppBar(
title: showSearch
? TextField(
focusNode: focusNode,
cursorColor: Colors.white,
onChanged: (String value) {
setState(() {
search = value;
});
},
decoration: const InputDecoration(
hintText: 'Search...',
border: InputBorder.none,
hintStyle: TextStyle(color: Colors.white),
),
)
: Text(routes[selected]['title']),
actions: [
IconButton(
icon: const Icon(Icons.search),
onPressed: toggleSearch,
),
],
2023-04-07 11:50:02 +12:00
),
2023-04-11 11:41:10 +12:00
body: getBody(),
));
2023-04-07 11:50:02 +12:00
}
}