2023-05-30 21:03:46 +02:00
|
|
|
import 'package:ernaehrung/android/components/meal_page_text/days_component.dart';
|
|
|
|
import 'package:ernaehrung/android/config/statistics.dart';
|
2023-05-12 18:12:28 +02:00
|
|
|
import 'package:ernaehrung/android/pages/nav_pages/progress_page.dart';
|
|
|
|
import 'package:ernaehrung/android/pages/nav_pages/today_page.dart';
|
2023-04-23 13:08:04 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'meal_plan_page.dart';
|
|
|
|
|
|
|
|
class MainPage extends StatefulWidget {
|
|
|
|
const MainPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
2023-04-29 15:56:04 +02:00
|
|
|
MainPageState createState() => MainPageState();
|
2023-04-23 13:08:04 +02:00
|
|
|
}
|
|
|
|
|
2023-04-29 15:56:04 +02:00
|
|
|
class MainPageState extends State<MainPage> {
|
2023-04-23 13:08:04 +02:00
|
|
|
List pages = [
|
2023-05-13 13:13:40 +02:00
|
|
|
const TodayPage(title: 'Today'),
|
2023-04-23 13:08:04 +02:00
|
|
|
const MealPlanPage(title: 'Meal Plan'),
|
2023-05-13 13:13:40 +02:00
|
|
|
const ProgressPage(title: 'Progress')
|
2023-04-23 13:08:04 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
int currentIndex = 0;
|
2023-05-29 22:04:44 +02:00
|
|
|
|
|
|
|
void onTap(int index) {
|
2023-04-23 13:08:04 +02:00
|
|
|
setState(() {
|
|
|
|
currentIndex = index;
|
2023-05-30 21:03:46 +02:00
|
|
|
if(currentIndex == 1){
|
|
|
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day);
|
2023-05-30 22:09:16 +02:00
|
|
|
}else if(currentIndex == 2){
|
|
|
|
StatisticsService.instance.updateProgressBoxValues();
|
2023-05-30 21:03:46 +02:00
|
|
|
}
|
2023-05-13 13:13:40 +02:00
|
|
|
pages[currentIndex];
|
2023-04-23 13:08:04 +02:00
|
|
|
});
|
|
|
|
}
|
2023-04-29 15:56:04 +02:00
|
|
|
|
2023-04-23 13:08:04 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-05-13 13:13:40 +02:00
|
|
|
title: Text(pages[currentIndex].title),
|
2023-05-29 22:04:44 +02:00
|
|
|
backgroundColor: Colors.grey.shade100,
|
|
|
|
),
|
|
|
|
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
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|