From b23f9ccdc1296f6900e899c81cc72501a03a2f7f Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sun, 5 Mar 2023 20:43:14 +0100 Subject: [PATCH] widget for line graph --- lib/widgets/line_chart_widget.dart | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/widgets/line_chart_widget.dart diff --git a/lib/widgets/line_chart_widget.dart b/lib/widgets/line_chart_widget.dart new file mode 100644 index 0000000..e03eabd --- /dev/null +++ b/lib/widgets/line_chart_widget.dart @@ -0,0 +1,39 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/settings_provider.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; + +class LineChart extends StatelessWidget { + final List dataSource; + final DateTime? Function(T, int) xValueMapper; + final num? Function(T, int) yValueMapper; + const LineChart( + {super.key, + required this.dataSource, + required this.xValueMapper, + required this.yValueMapper}); + + @override + Widget build(BuildContext context) { + SettingsProvider settingsProvider = context.watch(); + + return SfCartesianChart( + primaryXAxis: DateTimeAxis( + minimum: settingsProvider.settings?.startedAt, + maximum: settingsProvider.settings?.startedAt + .add(const Duration(days: 7 * 6)), + interval: 7, + dateFormat: DateFormat.Md('de'), + ), + primaryYAxis: + NumericAxis(isVisible: false, minimum: 0, maximum: 100, interval: 20), + series: [ + LineSeries( + dataSource: dataSource, + xValueMapper: xValueMapper, + yValueMapper: yValueMapper), + ], + ); + } +}