From c9ea73b9b2a2606b83b1db2ea68a53d427098ba1 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 12:50:50 +0100 Subject: [PATCH] Added Views for Models --- lib/providers/tasks_provider.dart | 15 +++++++++++++ lib/widgets/mood_view.dart | 32 ++++++++++++++++++++++++++ lib/widgets/relapse_view.dart | 20 +++++++++++++++++ lib/widgets/sleep_view.dart | 32 ++++++++++++++++++++++++++ lib/widgets/workout_view.dart | 37 +++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 lib/widgets/mood_view.dart create mode 100644 lib/widgets/relapse_view.dart create mode 100644 lib/widgets/sleep_view.dart create mode 100644 lib/widgets/workout_view.dart diff --git a/lib/providers/tasks_provider.dart b/lib/providers/tasks_provider.dart index f7cd673..590c4fc 100644 --- a/lib/providers/tasks_provider.dart +++ b/lib/providers/tasks_provider.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/models/relapse.dart'; import 'package:smoke_cess_app/models/sleep.dart'; import 'package:smoke_cess_app/models/workout.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart'; @@ -15,8 +16,14 @@ class TasksProvider extends ChangeNotifier { Pages.timer: true, }; + List moodHistory = []; + List sleepHistory = []; + List workoutHistory = []; + List relapseHistory = []; + TasksProvider(SettingsProvider? settingsProvider) { initTasks(); + initHistories(); } void setTaskDone(Pages taskName) { @@ -24,6 +31,14 @@ class TasksProvider extends ChangeNotifier { notifyListeners(); } + void initHistories() async { + moodHistory = await globals.databaseService.getMoodRecords(); + sleepHistory = await globals.databaseService.getSleepRecords(); + workoutHistory = await globals.databaseService.getWorkoutRecords(); + relapseHistory = await globals.databaseService.getRelapseRecords(); + notifyListeners(); + } + void initTasks() async { TZDateTime? moodToday = await getTodayMood(); if (moodToday != null) { diff --git a/lib/widgets/mood_view.dart b/lib/widgets/mood_view.dart new file mode 100644 index 0000000..14884b9 --- /dev/null +++ b/lib/widgets/mood_view.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; +import '../models/mood.dart'; +import '../providers/tasks_provider.dart'; + +class MoodView extends StatelessWidget { + const MoodView({super.key}); + + @override + Widget build(BuildContext context) { + var tasksModel = context.watch(); + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SfCartesianChart( + primaryXAxis: DateTimeAxis(), + 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}'); + }).toList()) + ], + ); + } +} diff --git a/lib/widgets/relapse_view.dart b/lib/widgets/relapse_view.dart new file mode 100644 index 0000000..dfa7355 --- /dev/null +++ b/lib/widgets/relapse_view.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/models/relapse.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; +import '../models/mood.dart'; +import '../providers/tasks_provider.dart'; + +class RelapseView extends StatelessWidget { + const RelapseView({super.key}); + + @override + Widget build(BuildContext context) { + var tasksModel = context.watch(); + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: tasksModel.relapseHistory.map((relapse) { + return Text('${relapse.date}: ${relapse.category}'); + }).toList()); + } +} diff --git a/lib/widgets/sleep_view.dart b/lib/widgets/sleep_view.dart new file mode 100644 index 0000000..90a005c --- /dev/null +++ b/lib/widgets/sleep_view.dart @@ -0,0 +1,32 @@ +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 '../providers/tasks_provider.dart'; + +class SleepView extends StatelessWidget { + const SleepView({super.key}); + + @override + Widget build(BuildContext context) { + var tasksModel = context.watch(); + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SfCartesianChart( + primaryXAxis: DateTimeAxis(), + series: [ + LineSeries( + dataSource: tasksModel.sleepHistory, + xValueMapper: (Sleep value, _) => value.date, + yValueMapper: (Sleep value, _) => value.sleepQualitiyValue) + ], + ), + Column( + children: tasksModel.sleepHistory.map((sleep) { + return Text('${sleep.date}: ${sleep.sleepQualitiyValue}'); + }).toList()) + ], + ); + } +} diff --git a/lib/widgets/workout_view.dart b/lib/widgets/workout_view.dart new file mode 100644 index 0000000..7f4f843 --- /dev/null +++ b/lib/widgets/workout_view.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/models/sleep.dart'; +import 'package:smoke_cess_app/models/workout.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; +import '../providers/tasks_provider.dart'; + +class WorkoutView extends StatelessWidget { + const WorkoutView({super.key}); + + @override + Widget build(BuildContext context) { + var 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) + ], + ), + Column( + children: tasksModel.sleepHistory.map((sleep) { + return Text('${sleep.date}: ${sleep.sleepQualitiyValue}'); + }).toList()) + ], + ); + } +}