91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
import 'package:ernaehrung/android/components/meal_page_text/days_component.dart';
|
|
import 'package:ernaehrung/android/config/statistics.dart';
|
|
import 'package:ernaehrung/android/pages/nav_pages/progress_page.dart';
|
|
import 'package:ernaehrung/android/pages/nav_pages/today_page.dart';
|
|
import 'package:ernaehrung/android/pages/settings.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_profile_picture/flutter_profile_picture.dart';
|
|
import 'package:hive/hive.dart';
|
|
import '../../models/user.dart';
|
|
import 'meal_plan_page.dart';
|
|
|
|
class MainPage extends StatefulWidget {
|
|
const MainPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
MainPageState createState() => MainPageState();
|
|
}
|
|
|
|
class MainPageState extends State<MainPage> {
|
|
List pages = [
|
|
const TodayPage(title: 'Today'),
|
|
const MealPlanPage(title: 'Meal Plan'),
|
|
const ProgressPage(title: 'Progress')
|
|
];
|
|
|
|
int currentIndex = 0;
|
|
|
|
void onTap(int index) {
|
|
setState(() {
|
|
currentIndex = index;
|
|
if (currentIndex == 1) {
|
|
StatisticsService.instance
|
|
.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
|
|
} else if (currentIndex == 2) {
|
|
StatisticsService.instance.updateProgressBoxValues();
|
|
}
|
|
pages[currentIndex];
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Box box = Hive.box<User>("USER_BOX");
|
|
return Scaffold(
|
|
extendBodyBehindAppBar: false,
|
|
appBar: AppBar(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(pages[currentIndex].title),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const SettingsPage()),
|
|
);
|
|
},
|
|
child: ProfilePicture(
|
|
name: "${box.get("FIRST_NAME_FIELD")}",
|
|
radius: 16,
|
|
fontsize: 14,
|
|
))
|
|
],
|
|
),
|
|
backgroundColor: Colors.transparent,
|
|
foregroundColor: Colors.grey.shade400,
|
|
elevation: 0,
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
|
|
child: pages[currentIndex],
|
|
),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: currentIndex,
|
|
selectedItemColor: Colors.black54,
|
|
unselectedItemColor: Colors.grey.withOpacity(0.5),
|
|
showSelectedLabels: false,
|
|
showUnselectedLabels: false,
|
|
elevation: 0,
|
|
onTap: onTap,
|
|
items: const [
|
|
BottomNavigationBarItem(icon: Icon(Icons.today), label: 'Today'),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.area_chart), label: 'Progress'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.apple), label: 'Meal Plan'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|