fmassive/lib/home_page.dart

107 lines
2.9 KiB
Dart
Raw Normal View History

2023-04-06 23:50:02 +00:00
import 'package:flutter/material.dart';
2023-04-10 23:41:10 +00:00
import 'package:fmassive/best_page.dart';
import 'package:fmassive/plans_page.dart';
2023-04-16 23:03:36 +00:00
import 'package:fmassive/set_list.dart';
2023-04-10 23:41:10 +00:00
import 'package:fmassive/settings_page.dart';
import 'package:fmassive/timer_page.dart';
import 'package:fmassive/workouts_page.dart';
2023-04-06 23:50:02 +00:00
2023-04-10 23:41:10 +00:00
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
2023-04-16 23:03:36 +00:00
createState() => _HomePage();
2023-04-10 23:41:10 +00:00
}
2023-04-16 23:03:36 +00:00
class _HomePage extends State<HomePage> {
2023-04-10 23:41:10 +00:00
bool showSearch = false;
int selected = 0;
String search = '';
final focusNode = FocusNode();
2023-04-06 23:50:02 +00:00
2023-04-07 03:56:17 +00:00
final List<Map<String, dynamic>> routes = [
2023-04-06 23:50:02 +00: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-10 23:41:10 +00:00
void toggleSearch() {
setState(() {
2023-04-11 01:14:26 +00:00
if (showSearch) search = '';
2023-04-10 23:41:10 +00:00
showSearch = !showSearch;
});
focusNode.requestFocus();
}
Widget getBody() {
switch (routes[selected]['title']) {
case 'Settings':
2023-04-13 05:23:26 +00:00
return SettingsPage(search: search);
2023-04-10 23:41:10 +00:00
case 'Timer':
return const TimerPage();
case 'Workouts':
return const WorkoutsPage();
case 'Best':
return const BestPage();
case 'Plans':
2023-04-13 06:58:26 +00:00
return PlansPage(search: search);
2023-04-10 23:41:10 +00:00
default:
2023-04-15 05:03:30 +00:00
return SetList(search: search);
2023-04-10 23:41:10 +00:00
}
}
2023-04-06 23:50:02 +00:00
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
2023-11-10 03:20:42 +00:00
drawerEdgeDragWidth: 200.0,
2023-04-06 23:50:02 +00:00
drawer: Drawer(
child: ListView.builder(
2023-04-07 03:56:17 +00:00
itemCount: routes.length,
2023-04-06 23:50:02 +00:00
itemBuilder: (context, index) {
return ListTile(
2023-04-10 23:41:10 +00:00
selected: selected == index,
2023-04-07 03:56:17 +00:00
leading: Icon(routes[index]['icon']),
title: Text(routes[index]['title']),
2023-04-06 23:50:02 +00:00
onTap: () {
2023-04-10 23:41:10 +00:00
setState(() {
selected = index;
});
2023-04-06 23:50:02 +00:00
Navigator.pop(context);
},
);
},
),
),
2023-04-10 23:41:10 +00: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-06 23:50:02 +00:00
),
2023-04-10 23:41:10 +00:00
body: getBody(),
2023-11-30 00:02:50 +00:00
),);
2023-04-06 23:50:02 +00:00
}
}