From d582b39f9e5fcd21b56055860f8a8dada38fffee Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 16 Dec 2024 21:10:31 +0100 Subject: [PATCH] wip graphs --- lib/pages/graphs_page.dart | 113 +++++++++++++++++++ lib/perdate/perdate_pageview_controller.dart | 8 ++ pubspec.lock | 16 +++ pubspec.yaml | 1 + 4 files changed, 138 insertions(+) create mode 100644 lib/pages/graphs_page.dart diff --git a/lib/pages/graphs_page.dart b/lib/pages/graphs_page.dart new file mode 100644 index 0000000..dc5e95b --- /dev/null +++ b/lib/pages/graphs_page.dart @@ -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 createState() => _GraphsPageWidgetState(); +} + +class _GraphsPageWidgetState extends State { + 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( + 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 = [ + '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; + }); + })); + } +} diff --git a/lib/perdate/perdate_pageview_controller.dart b/lib/perdate/perdate_pageview_controller.dart index aa02261..0f9e2ea 100644 --- a/lib/perdate/perdate_pageview_controller.dart +++ b/lib/perdate/perdate_pageview_controller.dart @@ -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().add( diff --git a/pubspec.lock b/pubspec.lock index 20e7c76..34efe46 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index 33d683b..43900c9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: