wip graphs

This commit is contained in:
Marco 2024-12-16 21:10:31 +01:00
parent 70c9c00304
commit 92433becba

113
lib/pages/graphs_page.dart Normal file
View File

@ -0,0 +1,113 @@
import 'dart:developer';
import 'package:calorimeter/utils/settings_bloc.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class GraphsPageWidget extends StatefulWidget {
const GraphsPageWidget({super.key});
@override
State<GraphsPageWidget> createState() => _GraphsPageWidgetState();
}
class _GraphsPageWidgetState extends State<GraphsPageWidget> {
late double data1;
@override
void initState() {
super.initState();
data1 = 40;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(100),
child: BlocBuilder<SettingsDataBloc, SettingsState>(
builder: (context, state) {
return BarChart(
BarChartData(
extraLinesData: ExtraLinesData(
horizontalLines: [
HorizontalLine(
y: state.kcalLimit,
color: Colors.red,
),
],
),
titlesData: FlTitlesData(
topTitles: AxisTitles(),
rightTitles: AxisTitles(),
bottomTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
getTitlesWidget: (value, meta) {
final titles = <String>[
'Mo',
'Di',
'Mi',
'Do',
'Fr',
'Sa',
'So'
];
return SideTitleWidget(
axisSide: meta.axisSide,
child: Text(
titles[value.toInt()],
),
);
},
),
),
),
gridData: FlGridData(
horizontalInterval: state.kcalLimit / 10,
drawVerticalLine: false,
),
maxY: state.kcalLimit + 500,
barGroups: [
BarChartGroupData(
x: 0,
barRods: [BarChartRodData(toY: state.kcalLimit)],
),
BarChartGroupData(
x: 1,
barRods: [BarChartRodData(toY: state.kcalLimit - 500)],
),
BarChartGroupData(
x: 2,
barRods: [BarChartRodData(toY: state.kcalLimit + 200)],
),
BarChartGroupData(
x: 3,
barRods: [BarChartRodData(toY: state.kcalLimit + data1)],
),
BarChartGroupData(
x: 4,
barRods: [BarChartRodData(toY: state.kcalLimit + data1)],
),
BarChartGroupData(
x: 5,
barRods: [BarChartRodData(toY: state.kcalLimit + data1)],
),
BarChartGroupData(
x: 6,
barRods: [BarChartRodData(toY: state.kcalLimit + data1)],
),
],
),
);
}),
),
floatingActionButton: FloatingActionButton(onPressed: () {
setState(() {
data1 *= 1.1;
});
}));
}
}