diff --git a/lib/widgets/line_chart_widget.dart b/lib/widgets/line_chart_widget.dart index e03eabd..de24754 100644 --- a/lib/widgets/line_chart_widget.dart +++ b/lib/widgets/line_chart_widget.dart @@ -5,14 +5,11 @@ 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}); + final List> series; + const LineChart({ + super.key, + required this.series, + }); @override Widget build(BuildContext context) { @@ -28,12 +25,7 @@ class LineChart extends StatelessWidget { ), primaryYAxis: NumericAxis(isVisible: false, minimum: 0, maximum: 100, interval: 20), - series: [ - LineSeries( - dataSource: dataSource, - xValueMapper: xValueMapper, - yValueMapper: yValueMapper), - ], + series: series, ); } } diff --git a/lib/widgets/view_form/mood_view.dart b/lib/widgets/view_form/mood_view.dart index b61f8b1..02cb557 100644 --- a/lib/widgets/view_form/mood_view.dart +++ b/lib/widgets/view_form/mood_view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/widgets/line_chart_widget.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; import 'package:smoke_cess_app/models/mood.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; @@ -13,15 +14,12 @@ class MoodView extends StatelessWidget { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - SfCartesianChart( - primaryXAxis: DateTimeAxis(), - series: [ - LineSeries( - dataSource: tasksModel.moodHistory, - xValueMapper: (Mood value, _) => value.date, - yValueMapper: (Mood value, _) => value.moodValue) - ], - ), + LineChart(series: [ + LineSeries( + dataSource: tasksModel.moodHistory, + xValueMapper: (Mood value, _) => value.date, + yValueMapper: (Mood value, _) => value.moodValue) + ]), Column( children: tasksModel.moodHistory.map((mood) { return Text('${mood.date}: ${mood.moodValue}'); diff --git a/lib/widgets/view_form/sleep_view.dart b/lib/widgets/view_form/sleep_view.dart index ffc9514..877d756 100644 --- a/lib/widgets/view_form/sleep_view.dart +++ b/lib/widgets/view_form/sleep_view.dart @@ -1,21 +1,21 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/models/sleep.dart'; -import 'package:syncfusion_flutter_charts/charts.dart'; +import 'package:smoke_cess_app/widgets/line_chart_widget.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; class SleepView extends StatelessWidget { const SleepView({super.key}); @override Widget build(BuildContext context) { - var tasksModel = context.watch(); + TasksProvider tasksModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - SfCartesianChart( - primaryXAxis: DateTimeAxis(), - series: [ + LineChart( + series: [ LineSeries( dataSource: tasksModel.sleepHistory, xValueMapper: (Sleep value, _) => value.date, diff --git a/lib/widgets/view_form/view_form_page.dart b/lib/widgets/view_form/view_form_page.dart index e58d5b0..778d21d 100644 --- a/lib/widgets/view_form/view_form_page.dart +++ b/lib/widgets/view_form/view_form_page.dart @@ -35,7 +35,8 @@ class ViewFormPage extends StatelessWidget { child: RoundAddButton( onPressed: tasksProvider.tasks[page] == true ? () => pageProvider.swap() - : () => showTaskDonePopup(context, page), + : () => pageProvider.swap(), + //: () => showTaskDonePopup(context, page), ), ) ]); diff --git a/lib/widgets/view_form/workout_view.dart b/lib/widgets/view_form/workout_view.dart index 8bc2fef..d0787e6 100644 --- a/lib/widgets/view_form/workout_view.dart +++ b/lib/widgets/view_form/workout_view.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/models/workout.dart'; +import 'package:smoke_cess_app/widgets/line_chart_widget.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; @@ -9,23 +10,20 @@ class WorkoutView extends StatelessWidget { @override Widget build(BuildContext context) { - var tasksModel = context.watch(); + TasksProvider tasksModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - SfCartesianChart( - primaryXAxis: DateTimeAxis(), - series: [ - LineSeries( - dataSource: tasksModel.workoutHistory, - xValueMapper: (Workout value, _) => value.date, - yValueMapper: (Workout value, _) => value.motivationBefore), - LineSeries( - dataSource: tasksModel.workoutHistory, - xValueMapper: (Workout value, _) => value.date, - yValueMapper: (Workout value, _) => value.motivationAfter) - ], - ), + LineChart(series: [ + LineSeries( + dataSource: tasksModel.workoutHistory, + xValueMapper: (Workout value, _) => value.date, + yValueMapper: (Workout value, _) => value.motivationBefore), + LineSeries( + dataSource: tasksModel.workoutHistory, + xValueMapper: (Workout value, _) => value.date, + yValueMapper: (Workout value, _) => value.motivationAfter) + ]), ], ); }