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