feat: add graphs #16

Merged
hernik merged 9 commits from dev into main 2023-12-25 21:43:25 +01:00
3 changed files with 24 additions and 8 deletions
Showing only changes of commit 9fa35660df - Show all commits

View file

@ -5,12 +5,16 @@ import 'package:prasule/pw/platformwidget.dart';
class PlatformButton extends PlatformWidget<TextButton, CupertinoButton> { class PlatformButton extends PlatformWidget<TextButton, CupertinoButton> {
final String text; final String text;
final void Function()? onPressed; final void Function()? onPressed;
final ButtonStyle? style;
const PlatformButton( const PlatformButton(
{super.key, required this.text, required this.onPressed}); {super.key, required this.text, required this.onPressed, this.style});
@override @override
TextButton createAndroidWidget(BuildContext context) => TextButton createAndroidWidget(BuildContext context) => TextButton(
TextButton(onPressed: onPressed, child: Text(text)); onPressed: onPressed,
style: style,
child: Text(text),
);
@override @override
CupertinoButton createIosWidget(BuildContext context) => CupertinoButton createIosWidget(BuildContext context) =>

View file

@ -1,4 +1,5 @@
import 'package:currency_picker/currency_picker.dart'; import 'package:currency_picker/currency_picker.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:fl_chart/fl_chart.dart'; import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
@ -102,7 +103,8 @@ class ExpensesLineChart extends StatelessWidget {
isStrokeCapRound: true, isStrokeCapRound: true,
dotData: const FlDotData(show: false), dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false), belowBarData: BarAreaData(show: false),
color: Theme.of(context).colorScheme.primary, color: Colors.green
.harmonizeWith(Theme.of(context).colorScheme.secondary),
spots: List.generate( spots: List.generate(
(yearly) ? 12 : DateTime(date.year, date.month, 0).day, (yearly) ? 12 : DateTime(date.year, date.month, 0).day,
(index) => FlSpot(index.toDouble(), incomeData[index]), (index) => FlSpot(index.toDouble(), incomeData[index]),
@ -115,7 +117,8 @@ class ExpensesLineChart extends StatelessWidget {
isStrokeCapRound: true, isStrokeCapRound: true,
dotData: const FlDotData(show: false), dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false), belowBarData: BarAreaData(show: false),
color: Theme.of(context).colorScheme.error, color: Colors.red
.harmonizeWith(Theme.of(context).colorScheme.secondary),
spots: List.generate( spots: List.generate(
(yearly) ? 12 : DateTime(date.year, date.month, 0).day, (yearly) ? 12 : DateTime(date.year, date.month, 0).day,
(index) => FlSpot(index.toDouble() + 1, expenseData[index]), (index) => FlSpot(index.toDouble() + 1, expenseData[index]),
@ -277,12 +280,14 @@ class ExpensesBarChart extends StatelessWidget {
if (incomeData.isNotEmpty) if (incomeData.isNotEmpty)
BarChartRodData( BarChartRodData(
toY: incomeData[index], toY: incomeData[index],
color: Theme.of(context).colorScheme.primary, color: Colors.green
.harmonizeWith(Theme.of(context).colorScheme.secondary),
), ),
if (expenseData.isNotEmpty) if (expenseData.isNotEmpty)
BarChartRodData( BarChartRodData(
toY: expenseData[index], toY: expenseData[index],
color: Theme.of(context).colorScheme.error, color: Colors.red
.harmonizeWith(Theme.of(context).colorScheme.secondary),
), ),
], ],
), ),

View file

@ -153,7 +153,7 @@ class _GraphViewState extends State<GraphView> {
strokeWidth: 5, strokeWidth: 5,
) )
: SizedBox( : SizedBox(
width: MediaQuery.of(context).size.width * 0.9, width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height, height: MediaQuery.of(context).size.height,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -212,6 +212,13 @@ class _GraphViewState extends State<GraphView> {
child: Column( child: Column(
children: [ children: [
PlatformButton( PlatformButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Theme.of(context).colorScheme.primary),
foregroundColor: MaterialStateProperty.all(
Theme.of(context)
.colorScheme
.onPrimary)),
text: (yearly) text: (yearly)
? DateFormat.y(locale).format(_selectedDate) ? DateFormat.y(locale).format(_selectedDate)
: DateFormat.yMMMM(locale) : DateFormat.yMMMM(locale)