Flutter-Ernaehrungsapp/lib/pages/nav_pages/main_page.dart

101 lines
3.0 KiB
Dart
Raw Normal View History

2023-06-25 14:43:07 +02:00
import 'package:ernaehrung/pages/nav_pages/subpages/statistics_page/statistics_page.dart';
import 'package:ernaehrung/pages/nav_pages/subpages/today_page/today_page.dart';
2023-04-23 13:08:04 +02:00
import 'package:flutter/material.dart';
2023-06-25 14:43:07 +02:00
import '../../services/statistics.dart';
import 'subpages/progress_page/sub_components/charts/sub_components/tabs/timespan_tabs.dart';
import '../user_data_form/user_data_form.dart';
import 'subpages/progress_page/progress_page.dart';
2023-04-23 13:08:04 +02:00
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
MainPageState createState() => MainPageState();
2023-04-23 13:08:04 +02:00
}
class MainPageState extends State<MainPage> {
2023-04-23 13:08:04 +02:00
List pages = [
2023-06-02 19:21:06 +02:00
const TodayPage(title: 'Essensplan'),
2023-06-25 14:43:07 +02:00
const ProgressPage(title: 'Gesamtübersicht'),
const StatisticsPage(title: 'Statistiken')
2023-04-23 13:08:04 +02:00
];
int currentIndex = 0;
2023-05-29 22:04:44 +02:00
2023-06-03 00:51:26 +02:00
void onTap(int index) async {
2023-04-23 13:08:04 +02:00
setState(() {
currentIndex = index;
2023-06-03 00:40:40 +02:00
if (currentIndex == 1) {
2023-06-25 14:43:07 +02:00
DataService.instance
2023-06-03 00:40:40 +02:00
.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
} else if (currentIndex == 2) {
2023-06-25 14:43:07 +02:00
DataService.instance.updateProgressBoxValues();
2023-05-30 21:03:46 +02:00
}
pages[currentIndex];
2023-04-23 13:08:04 +02:00
});
}
2023-04-23 13:08:04 +02:00
@override
Widget build(BuildContext context) {
return Scaffold(
2023-06-02 01:42:56 +02:00
extendBodyBehindAppBar: false,
2023-04-23 13:08:04 +02:00
appBar: AppBar(
2023-06-03 00:40:40 +02:00
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
2023-06-02 18:38:19 +02:00
pages[currentIndex].title,
2023-06-25 14:43:07 +02:00
style: const TextStyle(
2023-06-02 18:38:19 +02:00
color: Colors.black
),
),
2023-06-03 00:40:40 +02:00
ElevatedButton(
2023-06-16 12:10:48 +02:00
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SettingsPage()),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green, // Set the background color to green
),
child: Row(
children: const [
Icon(
Icons.account_circle,
size: 30,
color: Colors.white,
),
],
),
)
2023-06-03 00:40:40 +02:00
],
2023-06-02 18:38:19 +02:00
),
2023-06-02 01:42:56 +02:00
backgroundColor: Colors.transparent,
foregroundColor: Colors.grey.shade400,
elevation: 0,
2023-05-29 22:04:44 +02:00
),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
child: pages[currentIndex],
2023-04-23 13:08:04 +02:00
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
selectedItemColor: Colors.black54,
unselectedItemColor: Colors.grey.withOpacity(0.5),
showSelectedLabels: false,
showUnselectedLabels: false,
elevation: 0,
onTap: onTap,
items: const [
2023-05-29 22:04:44 +02:00
BottomNavigationBarItem(icon: Icon(Icons.today), label: 'Today'),
2023-04-23 13:08:04 +02:00
BottomNavigationBarItem(
2023-05-29 22:04:44 +02:00
icon: Icon(Icons.area_chart), label: 'Progress'),
BottomNavigationBarItem(icon: Icon(Icons.apple), label: 'Meal Plan'),
2023-04-23 13:08:04 +02:00
],
),
);
}
}