73 lines
2.0 KiB
Dart
73 lines
2.0 KiB
Dart
import 'package:ernaehrung/android/components/meal_page_text/days_text_component.dart';
|
|
import 'package:ernaehrung/android/config/statistics.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
enum TimeSpan {
|
|
day,
|
|
week,
|
|
month
|
|
}
|
|
|
|
|
|
class DaysMealPageComponent extends StatefulWidget {
|
|
const DaysMealPageComponent({Key? key}) : super(key: key);
|
|
@override
|
|
State<StatefulWidget> createState() => _DaysMealPageState();
|
|
}
|
|
|
|
|
|
class _DaysMealPageState extends State<DaysMealPageComponent> {
|
|
int activatedIndex = 0;
|
|
|
|
void updateValue(int index) {
|
|
setState(() {
|
|
activatedIndex = index;
|
|
if(activatedIndex == 0){
|
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day);
|
|
}else if(activatedIndex == 1){
|
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.week);
|
|
}else if(activatedIndex == 2){
|
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.month);
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
DaysTextComponent(
|
|
timeSpan: TimeSpan.day,
|
|
textColor: activatedIndex == 0
|
|
? const Color(0xff47a44b)
|
|
: const Color(0xff000000),
|
|
onPressed: updateValue,
|
|
index: 0
|
|
|
|
),
|
|
DaysTextComponent(
|
|
timeSpan: TimeSpan.week,
|
|
textColor: activatedIndex == 1
|
|
? const Color(0xff47a44b)
|
|
: const Color(0xff000000),
|
|
onPressed: updateValue,
|
|
index: 1
|
|
),
|
|
DaysTextComponent(
|
|
timeSpan: TimeSpan.month,
|
|
textColor: activatedIndex == 2
|
|
? const Color(0xff47a44b)
|
|
: const Color(0xff000000),
|
|
onPressed: updateValue,
|
|
index: 2
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|