wip graphs

This commit is contained in:
Marco 2024-12-16 21:10:31 +01:00
parent cfc712458f
commit d582b39f9e
4 changed files with 138 additions and 0 deletions

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;
});
}));
}
}

View File

@ -7,6 +7,7 @@ import 'package:calorimeter/perdate/perdate_pageview.dart';
import 'package:calorimeter/utils/app_drawer.dart';
import 'package:calorimeter/utils/calendar_floating_button.dart';
import 'package:calorimeter/utils/date_time_helper.dart';
import 'package:calorimeter/pages/graphs_page.dart';
import 'package:calorimeter/utils/rectangular_notch_shape.dart';
import 'package:calorimeter/utils/scan_food_floating_button.dart';
import 'package:calorimeter/utils/sum_widget.dart';
@ -74,6 +75,13 @@ class PerDatePageViewController extends StatelessWidget {
),
drawer: const AppDrawer(),
floatingActionButton: OverflowBar(children: [
FloatingActionButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const GraphsPageWidget()));
},
child: Icon(Icons.bar_chart)),
const SizedBox(width: 8),
ScanFoodFAB(
onPressed: () {
context.read<FoodEntryBloc>().add(

View File

@ -134,6 +134,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.6"
equatable:
dependency: transitive
description:
name: equatable
sha256: "567c64b3cb4cf82397aac55f4f0cbd3ca20d77c6c03bedbc4ceaddc08904aef7"
url: "https://pub.dev"
source: hosted
version: "2.0.7"
fake_async:
dependency: transitive
description:
@ -166,6 +174,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
fl_chart:
dependency: "direct main"
description:
name: fl_chart
sha256: "74959b99b92b9eebeed1a4049426fd67c4abc3c5a0f4d12e2877097d6a11ae08"
url: "https://pub.dev"
source: hosted
version: "0.69.2"
flutter:
dependency: "direct main"
description: flutter

View File

@ -20,6 +20,7 @@ dependencies:
provider: ^6.1.2
test: ^1.25.7
go_router: ^14.3.0
fl_chart: ^0.69.2
dev_dependencies:
flutter_test: