From 175735f4b933b8dca568a9f49d013eae78b2286e Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 18:35:03 +0100 Subject: [PATCH 1/8] Added TaskProvider and Pages enum --- lib/main.dart | 8 +++-- lib/mock/db_mock.dart | 8 +++-- lib/models/mood.dart | 2 ++ lib/models/sleep.dart | 2 ++ lib/models/workout.dart | 4 ++- lib/pages/main_page.dart | 6 ++-- lib/providers/task_provider.dart | 56 ++++++++++++++++++++++++++++++ lib/services/database_service.dart | 9 +++++ lib/services/date_service.dart | 20 +++++++++++ lib/services/pages_service.dart | 38 ++++++++++++++------ 10 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 lib/providers/task_provider.dart diff --git a/lib/main.dart b/lib/main.dart index a1cf5ac..e52b7e6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/pages/main_page.dart'; +import 'package:smoke_cess_app/providers/task_provider.dart'; import 'package:smoke_cess_app/services/notification_service.dart'; import 'package:timezone/data/latest.dart' as tz; import 'globals.dart' as globals; @@ -25,8 +26,11 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: _title, - home: ChangeNotifierProvider( - create: (context) => SettingsProvider(), + home: MultiProvider( + providers: [ + ChangeNotifierProvider(create: (context) => SettingsProvider()), + ChangeNotifierProvider(create: (context) => TaskProvider()), + ], child: const MyHomePage(), )); } diff --git a/lib/mock/db_mock.dart b/lib/mock/db_mock.dart index 313cece..4e5d0e6 100644 --- a/lib/mock/db_mock.dart +++ b/lib/mock/db_mock.dart @@ -1,4 +1,3 @@ -import 'package:smoke_cess_app/interface/db_record.dart'; import 'package:smoke_cess_app/models/mood.dart'; import 'package:smoke_cess_app/models/relapse.dart'; import 'package:smoke_cess_app/models/sleep.dart'; @@ -17,7 +16,7 @@ class DatabaseMock implements DatabaseService { final List _moodRecords = []; final List _sleepRecords = []; final List _relapseRecords = []; - final List _workoutRecords = []; + final List _workoutRecords = []; @override Future addMood(Mood mood) { @@ -60,4 +59,9 @@ class DatabaseMock implements DatabaseService { Future> getRelapseRecords() { return Future.value(_relapseRecords); } + + @override + Future> getWorkoutRecords() { + return Future.value(_workoutRecords); + } } diff --git a/lib/models/mood.dart b/lib/models/mood.dart index 562b2b4..7f5e7a6 100644 --- a/lib/models/mood.dart +++ b/lib/models/mood.dart @@ -7,6 +7,8 @@ class Mood implements DatabaseRecord { Mood(this._moodValue, this._comment, this._date); + DateTime get date => _date; + @override factory Mood.fromDatabase(Map map) { DateTime date = DateTime.parse(map['date']); diff --git a/lib/models/sleep.dart b/lib/models/sleep.dart index 3474b03..74fd6cb 100644 --- a/lib/models/sleep.dart +++ b/lib/models/sleep.dart @@ -11,6 +11,8 @@ class Sleep implements DatabaseRecord { Sleep(this._sleepQualityValue, this._comment, this._date, this._sleptAt, this._wokeUpAt); + DateTime get date => _date; + @override factory Sleep.fromDatabase(Map map) { DateTime date = DateTime.parse(map['date']); diff --git a/lib/models/workout.dart b/lib/models/workout.dart index 0bba86a..39ef628 100644 --- a/lib/models/workout.dart +++ b/lib/models/workout.dart @@ -7,8 +7,10 @@ class Workout implements DatabaseRecord { Workout(this._motivationBefore, this._motivationAfter, this._workoutDate); + DateTime get date => _workoutDate; + @override - factory Workout.fromMap(Map map) { + factory Workout.fromDatabase(Map map) { return Workout(map['_workoutDuration'], map['_motivationBefore'], map['_motivationAfter']); } diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index b45b479..1d55df5 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -36,7 +36,7 @@ class MyHomePageState extends State { return Scaffold( appBar: AppBar( title: Text( - '${pages.keys.elementAt(_selectedIndex)} ${_isConfigured ? "Gruppe $group" : ""}')), + '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe $group" : ""}')), body: Center( child: SingleChildScrollView( child: pages.values.elementAt(_selectedIndex)['page'])), @@ -45,9 +45,9 @@ class MyHomePageState extends State { selectedIndex: _selectedIndex, destinations: pages.keys.map((key) { return NavigationDestination( - icon: pages[key]!['icon'] ?? + icon: pages[key]?['icon'] ?? const Icon(Icons.disabled_by_default), - label: key); + label: pages[key]?['title']); }).toList()), ); } diff --git a/lib/providers/task_provider.dart b/lib/providers/task_provider.dart new file mode 100644 index 0000000..cf27964 --- /dev/null +++ b/lib/providers/task_provider.dart @@ -0,0 +1,56 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/models/sleep.dart'; +import 'package:smoke_cess_app/models/workout.dart'; +import 'package:smoke_cess_app/services/date_service.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; +import 'package:timezone/browser.dart'; +import '../globals.dart' as globals; +import '../models/mood.dart'; + +class TaskProvider extends ChangeNotifier { + TaskProvider() { + initTasks(); + } + + void setTaksDone(Pages taskName) { + pages[taskName]?['todo'] = false; + notifyListeners(); + } + + void initTasks() { + pages.forEach((key, value) async { + if (!value['todo']) { + switch (key) { + case Pages.mood: + TZDateTime? moodToday = await getTodayMood(); + if (moodToday != null) { + List moodList = + await globals.databaseService.getMoodRecords(); + Mood mood = moodList.last; + pages[key]?['todo'] = !isSameDay(moodToday, mood.date); + } + break; + case Pages.sleep: + TZDateTime? sleepToday = await getTodayMood(); + if (sleepToday != null) { + List sleepList = + await globals.databaseService.getSleepRecords(); + Sleep sleep = sleepList.last; + pages[key]?['todo'] = !isSameDay(sleepToday, sleep.date); + } + break; + case Pages.timer: + { + List workoutList = + await globals.databaseService.getWorkoutRecords(); + Workout mood = workoutList.last; + pages[key]?['todo'] = !isSameDay(DateTime.now(), mood.date); + break; + } + default: + } + } + }); + notifyListeners(); + } +} diff --git a/lib/services/database_service.dart b/lib/services/database_service.dart index 3996883..acc3ca0 100644 --- a/lib/services/database_service.dart +++ b/lib/services/database_service.dart @@ -63,6 +63,15 @@ class DatabaseService { return relapseList; } + Future> getWorkoutRecords() async { + Database db = await instance.database; + var workoutRecords = await db.query('workout'); + List workoutList = workoutRecords.isNotEmpty + ? workoutRecords.map((e) => Workout.fromDatabase(e)).toList() + : []; + return workoutList; + } + Future addMood(Mood mood) async { Database db = await instance.database; return await db.insert('mood', mood.toMap()); diff --git a/lib/services/date_service.dart b/lib/services/date_service.dart index 0fd108e..b5e254f 100644 --- a/lib/services/date_service.dart +++ b/lib/services/date_service.dart @@ -13,6 +13,12 @@ const weekDays = { "Sonntag": 7, }; +bool isSameDay(DateTime? dateA, DateTime? dateB) { + return dateA?.year == dateB?.year && + dateA?.month == dateB?.month && + dateA?.day == dateB?.day; +} + Future> getDatesforMood() async { final List? selectedDays = await getMoodQueryDaysCategories(); final int? selectedHours = await getMoodQueryHours(); @@ -27,6 +33,20 @@ Future> getDatesforSleep() async { return createTZDateTimes(selectedDays, selectedHours, selectedMinutes); } +Future getTodayMood() async { + List moodDates = await getDatesforMood(); + Iterable today = + moodDates.where((element) => isSameDay(element, DateTime.now())); + return today.isNotEmpty ? today.first : null; +} + +Future getTodaySleep() async { + List sleepDates = await getDatesforSleep(); + Iterable today = + sleepDates.where((element) => isSameDay(element, DateTime.now())); + return today.isNotEmpty ? today.first : null; +} + List createTZDateTimes( List? selectedDays, int? selectedHours, int? selectedMinutes) { final List tzDateTimes = []; diff --git a/lib/services/pages_service.dart b/lib/services/pages_service.dart index 8f3ab37..c29795a 100644 --- a/lib/services/pages_service.dart +++ b/lib/services/pages_service.dart @@ -5,25 +5,43 @@ import '../pages/relapse_page.dart'; import '../pages/scanner_page.dart'; import '../pages/sleep_page.dart'; -const pages = { - 'Stimmung': { +enum Pages { + mood, + sleep, + relapse, + timer, + settings, +} + +const Map> pages = { + Pages.mood: { + 'title': 'Stimmung', 'page': MoodPage(), - 'icon': Icon(Icons.mood_outlined, color: Colors.black) + 'icon': Icon(Icons.mood_outlined, color: Colors.black), + 'todo': false, }, - 'Schlaf': { + Pages.sleep: { + 'title': 'Schlaf', 'page': SleepPage(), - 'icon': Icon(Icons.bedtime_outlined, color: Colors.black) + 'icon': Icon(Icons.bedtime_outlined, color: Colors.black), + 'todo': false, }, - 'Timer': { + Pages.relapse: { + 'title': 'Timer', 'page': IntervalTimerPage(), - 'icon': Icon(Icons.timer_outlined, color: Colors.black) + 'icon': Icon(Icons.timer_outlined, color: Colors.black), + 'todo': false, }, - 'Rückfall': { + Pages.timer: { + 'title': 'Rückfall', 'page': RelapsePage(), 'icon': Icon(Icons.smoke_free_outlined, color: Colors.black), + 'todo': false, }, - 'Scanner': { + Pages.settings: { + 'title': 'Scanner', 'page': ScannerPage(), - 'icon': Icon(Icons.camera_alt_outlined, color: Colors.black) + 'icon': Icon(Icons.camera_alt_outlined, color: Colors.black), + 'todo': false, }, }; From c3fde53bec01c2612f5de33ada7489a79652b3fc Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:31:47 +0100 Subject: [PATCH 2/8] added TasksProvider to MainPage --- assets/group3.json | 2 +- lib/main.dart | 4 +-- lib/pages/main_page.dart | 28 +++++++++++++--- lib/providers/task_provider.dart | 56 ------------------------------- lib/providers/tasks_provider.dart | 55 ++++++++++++++++++++++++++++++ lib/services/pages_service.dart | 9 ++--- 6 files changed, 84 insertions(+), 70 deletions(-) delete mode 100644 lib/providers/task_provider.dart create mode 100644 lib/providers/tasks_provider.dart diff --git a/assets/group3.json b/assets/group3.json index 55ce9e0..30e9886 100644 --- a/assets/group3.json +++ b/assets/group3.json @@ -7,7 +7,7 @@ }, "relapse_categories": ["App stresst mich", "langeweile", "lunge braucht es"], "mood_query": { - "days": ["Montag", "Freitag"], + "days": ["Montag", "Donnerstag"], "hours": 10, "minutes": 30 }, diff --git a/lib/main.dart b/lib/main.dart index e52b7e6..0c574ce 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/pages/main_page.dart'; -import 'package:smoke_cess_app/providers/task_provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/services/notification_service.dart'; import 'package:timezone/data/latest.dart' as tz; import 'globals.dart' as globals; @@ -29,7 +29,7 @@ class MyApp extends StatelessWidget { home: MultiProvider( providers: [ ChangeNotifierProvider(create: (context) => SettingsProvider()), - ChangeNotifierProvider(create: (context) => TaskProvider()), + ChangeNotifierProvider(create: (context) => TasksProvider()), ], child: const MyHomePage(), )); diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 1d55df5..13defdb 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -1,6 +1,7 @@ import 'package:awesome_dialog/awesome_dialog.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart'; @@ -31,12 +32,12 @@ class MyHomePageState extends State { @override Widget build(BuildContext context) { var settingsModel = context.watch(); - var group = settingsModel.settings?.group; + var tasksModel = context.watch(); _isConfigured = settingsModel.initialized; return Scaffold( appBar: AppBar( title: Text( - '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe $group" : ""}')), + '${pages.values.elementAt(_selectedIndex)['title']} + ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), body: Center( child: SingleChildScrollView( child: pages.values.elementAt(_selectedIndex)['page'])), @@ -45,10 +46,29 @@ class MyHomePageState extends State { selectedIndex: _selectedIndex, destinations: pages.keys.map((key) { return NavigationDestination( - icon: pages[key]?['icon'] ?? - const Icon(Icons.disabled_by_default), + icon: tasksModel.tasks[key] ?? false + ? MyToDoIcon(pages[key]?['icon']) + : pages[key]!['icon'], label: pages[key]?['title']); }).toList()), ); } } + +class MyToDoIcon extends StatelessWidget { + final Icon _icon; + const MyToDoIcon(this._icon, {super.key}); + + @override + Widget build(BuildContext context) { + return Stack(children: [ + _icon, + const Positioned( + // draw a red marble + top: 0.0, + right: 0.0, + child: Icon(Icons.brightness_1, size: 10.0, color: Colors.redAccent), + ) + ]); + } +} diff --git a/lib/providers/task_provider.dart b/lib/providers/task_provider.dart deleted file mode 100644 index cf27964..0000000 --- a/lib/providers/task_provider.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:smoke_cess_app/models/sleep.dart'; -import 'package:smoke_cess_app/models/workout.dart'; -import 'package:smoke_cess_app/services/date_service.dart'; -import 'package:smoke_cess_app/services/pages_service.dart'; -import 'package:timezone/browser.dart'; -import '../globals.dart' as globals; -import '../models/mood.dart'; - -class TaskProvider extends ChangeNotifier { - TaskProvider() { - initTasks(); - } - - void setTaksDone(Pages taskName) { - pages[taskName]?['todo'] = false; - notifyListeners(); - } - - void initTasks() { - pages.forEach((key, value) async { - if (!value['todo']) { - switch (key) { - case Pages.mood: - TZDateTime? moodToday = await getTodayMood(); - if (moodToday != null) { - List moodList = - await globals.databaseService.getMoodRecords(); - Mood mood = moodList.last; - pages[key]?['todo'] = !isSameDay(moodToday, mood.date); - } - break; - case Pages.sleep: - TZDateTime? sleepToday = await getTodayMood(); - if (sleepToday != null) { - List sleepList = - await globals.databaseService.getSleepRecords(); - Sleep sleep = sleepList.last; - pages[key]?['todo'] = !isSameDay(sleepToday, sleep.date); - } - break; - case Pages.timer: - { - List workoutList = - await globals.databaseService.getWorkoutRecords(); - Workout mood = workoutList.last; - pages[key]?['todo'] = !isSameDay(DateTime.now(), mood.date); - break; - } - default: - } - } - }); - notifyListeners(); - } -} diff --git a/lib/providers/tasks_provider.dart b/lib/providers/tasks_provider.dart new file mode 100644 index 0000000..182b8ec --- /dev/null +++ b/lib/providers/tasks_provider.dart @@ -0,0 +1,55 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/models/sleep.dart'; +import 'package:smoke_cess_app/models/workout.dart'; +import 'package:smoke_cess_app/services/date_service.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; +import 'package:timezone/browser.dart'; +import '../globals.dart' as globals; +import '../models/mood.dart'; + +class TasksProvider extends ChangeNotifier { + Map tasks = { + Pages.mood: true, + Pages.sleep: true, + Pages.timer: true, + }; + + TasksProvider() { + initTasks(); + } + + void setTaksDone(Pages taskName) { + tasks[taskName] = false; + notifyListeners(); + } + + void initTasks() async { + TZDateTime? moodToday = await getTodayMood(); + if (moodToday != null) { + List moodList = await globals.databaseService.getMoodRecords(); + if (moodList.isNotEmpty) { + Mood mood = moodList.last; + tasks[Pages.mood] = isSameDay(moodToday, mood.date); + } + } else { + tasks[Pages.mood] = false; + } + TZDateTime? sleepToday = await getTodayMood(); + if (sleepToday != null) { + List sleepList = await globals.databaseService.getSleepRecords(); + if (sleepList.isNotEmpty) { + Sleep sleep = sleepList.last; + tasks[Pages.sleep] = isSameDay(sleepToday, sleep.date); + } + } else { + tasks[Pages.sleep] = false; + } + List workoutList = + await globals.databaseService.getWorkoutRecords(); + if (workoutList.isNotEmpty) { + Workout mood = workoutList.last; + tasks[Pages.timer] = isSameDay(DateTime.now(), mood.date); + } + notifyListeners(); + } +} diff --git a/lib/services/pages_service.dart b/lib/services/pages_service.dart index c29795a..0c19383 100644 --- a/lib/services/pages_service.dart +++ b/lib/services/pages_service.dart @@ -18,30 +18,25 @@ const Map> pages = { 'title': 'Stimmung', 'page': MoodPage(), 'icon': Icon(Icons.mood_outlined, color: Colors.black), - 'todo': false, }, Pages.sleep: { 'title': 'Schlaf', 'page': SleepPage(), 'icon': Icon(Icons.bedtime_outlined, color: Colors.black), - 'todo': false, }, - Pages.relapse: { + Pages.timer: { 'title': 'Timer', 'page': IntervalTimerPage(), 'icon': Icon(Icons.timer_outlined, color: Colors.black), - 'todo': false, }, - Pages.timer: { + Pages.relapse: { 'title': 'Rückfall', 'page': RelapsePage(), 'icon': Icon(Icons.smoke_free_outlined, color: Colors.black), - 'todo': false, }, Pages.settings: { 'title': 'Scanner', 'page': ScannerPage(), 'icon': Icon(Icons.camera_alt_outlined, color: Colors.black), - 'todo': false, }, }; From 1a7f98c5381ec017aeb9d2a784949b2eb1d069e9 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:32:13 +0100 Subject: [PATCH 3/8] Fixed wrong title --- lib/pages/main_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 13defdb..82b4990 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -37,7 +37,7 @@ class MyHomePageState extends State { return Scaffold( appBar: AppBar( title: Text( - '${pages.values.elementAt(_selectedIndex)['title']} + ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), + '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), body: Center( child: SingleChildScrollView( child: pages.values.elementAt(_selectedIndex)['page'])), From d18bf8f56d372e1c3b19036537c6cedd6a777305 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:57:24 +0100 Subject: [PATCH 4/8] Update Tasks when Settings update --- lib/main.dart | 6 +++++- lib/providers/tasks_provider.dart | 11 ++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0c574ce..c5a19b7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,7 +29,11 @@ class MyApp extends StatelessWidget { home: MultiProvider( providers: [ ChangeNotifierProvider(create: (context) => SettingsProvider()), - ChangeNotifierProvider(create: (context) => TasksProvider()), + ChangeNotifierProxyProvider( + create: (context) => TasksProvider(null), + update: (context, value, TasksProvider? previous) => + TasksProvider(value), + ), ], child: const MyHomePage(), )); diff --git a/lib/providers/tasks_provider.dart b/lib/providers/tasks_provider.dart index 182b8ec..8ae2a04 100644 --- a/lib/providers/tasks_provider.dart +++ b/lib/providers/tasks_provider.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.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'; import 'package:smoke_cess_app/services/date_service.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:timezone/browser.dart'; @@ -14,7 +15,7 @@ class TasksProvider extends ChangeNotifier { Pages.timer: true, }; - TasksProvider() { + TasksProvider(SettingsProvider? settingsProvider) { initTasks(); } @@ -29,17 +30,17 @@ class TasksProvider extends ChangeNotifier { List moodList = await globals.databaseService.getMoodRecords(); if (moodList.isNotEmpty) { Mood mood = moodList.last; - tasks[Pages.mood] = isSameDay(moodToday, mood.date); + tasks[Pages.mood] = !isSameDay(moodToday, mood.date); } } else { tasks[Pages.mood] = false; } - TZDateTime? sleepToday = await getTodayMood(); + TZDateTime? sleepToday = await getTodaySleep(); if (sleepToday != null) { List sleepList = await globals.databaseService.getSleepRecords(); if (sleepList.isNotEmpty) { Sleep sleep = sleepList.last; - tasks[Pages.sleep] = isSameDay(sleepToday, sleep.date); + tasks[Pages.sleep] = !isSameDay(sleepToday, sleep.date); } } else { tasks[Pages.sleep] = false; @@ -48,7 +49,7 @@ class TasksProvider extends ChangeNotifier { await globals.databaseService.getWorkoutRecords(); if (workoutList.isNotEmpty) { Workout mood = workoutList.last; - tasks[Pages.timer] = isSameDay(DateTime.now(), mood.date); + tasks[Pages.timer] = !isSameDay(DateTime.now(), mood.date); } notifyListeners(); } From e8a123413c9959b26f083aaaca20dced75910bba Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 20:16:46 +0100 Subject: [PATCH 5/8] Update when submiting form --- lib/widgets/mood_form.dart | 4 ++++ lib/widgets/relapse_form.dart | 9 ++++++-- lib/widgets/sleep_form.dart | 4 ++++ lib/widgets/submit_form_button.dart | 33 +++++++++++++++++------------ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index b461ce7..4661678 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/widgets/slider.dart'; import 'package:smoke_cess_app/widgets/submit_form_button.dart'; import 'package:smoke_cess_app/widgets/text_formfield.dart'; @@ -13,6 +15,7 @@ class MoodForm extends StatelessWidget { @override Widget build(BuildContext context) { var inputModel = context.watch(); + var tasksModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -30,6 +33,7 @@ class MoodForm extends StatelessWidget { ), SubmitFormButton( submitCallback: inputModel.saveMood, + updateTasks: () => tasksModel.setTaksDone(Pages.mood), ) ], ); diff --git a/lib/widgets/relapse_form.dart b/lib/widgets/relapse_form.dart index 88e555c..38d3492 100644 --- a/lib/widgets/relapse_form.dart +++ b/lib/widgets/relapse_form.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/widgets/drop_down.dart'; import 'package:smoke_cess_app/widgets/submit_form_button.dart'; import 'package:smoke_cess_app/widgets/text_formfield.dart'; - import '../providers/input_provider.dart'; import '../providers/settings_provider.dart'; +import '../services/pages_service.dart'; import 'elevated_card.dart'; class RelapseForm extends StatelessWidget { @@ -15,6 +16,7 @@ class RelapseForm extends StatelessWidget { Widget build(BuildContext context) { var inputModel = context.watch(); var settingsModel = context.watch(); + var tasksModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -29,7 +31,10 @@ class RelapseForm extends StatelessWidget { const SizedBox( height: 80, ), - SubmitFormButton(submitCallback: inputModel.saveRelapse) + SubmitFormButton( + submitCallback: inputModel.saveRelapse, + updateTasks: () => tasksModel.setTaksDone(Pages.mood), + ) ], ); } diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 8b4389c..b578e2c 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/widgets/elevated_card.dart'; import 'package:smoke_cess_app/widgets/slider.dart'; import 'package:smoke_cess_app/widgets/submit_form_button.dart'; @@ -7,6 +8,7 @@ import 'package:smoke_cess_app/widgets/text_formfield.dart'; import 'package:smoke_cess_app/widgets/timepicker.dart'; import '../providers/input_provider.dart'; +import '../services/pages_service.dart'; class SleepForm extends StatelessWidget { const SleepForm({Key? key}) : super(key: key); @@ -14,6 +16,7 @@ class SleepForm extends StatelessWidget { @override Widget build(BuildContext context) { InputProvider inputModel = context.watch(); + TasksProvider tasksModel = context.watch(); String wokeUpKey = 'wokeUpAt'; String sleptKey = 'sleptAt'; @@ -44,6 +47,7 @@ class SleepForm extends StatelessWidget { ), SubmitFormButton( submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey), + updateTasks: () => tasksModel.setTaksDone(Pages.mood), ) ], ); diff --git a/lib/widgets/submit_form_button.dart b/lib/widgets/submit_form_button.dart index 3242b18..b5bb593 100644 --- a/lib/widgets/submit_form_button.dart +++ b/lib/widgets/submit_form_button.dart @@ -3,7 +3,9 @@ import 'package:flutter/material.dart'; class SubmitFormButton extends StatelessWidget { final Future Function() submitCallback; - const SubmitFormButton({super.key, required this.submitCallback}); + final void Function() updateTasks; + const SubmitFormButton( + {super.key, required this.submitCallback, required this.updateTasks}); @override Widget build(BuildContext context) { @@ -12,19 +14,22 @@ class SubmitFormButton extends StatelessWidget { child: ElevatedButton( onPressed: () async { int success = await submitCallback(); - success != 0 - ? AwesomeDialog( - context: context, - dialogType: DialogType.success, - title: 'Gespeichert', - desc: 'Der Eintrag wurde erfolgreich gespeichert', - ).show() - : AwesomeDialog( - context: context, - dialogType: DialogType.error, - title: 'Fehler', - desc: 'Der Eintrag konnte nicht gespeichert werden', - ).show(); + if (success != 0) { + AwesomeDialog( + context: context, + dialogType: DialogType.success, + title: 'Gespeichert', + desc: 'Der Eintrag wurde erfolgreich gespeichert', + ).show(); + updateTasks(); + } else { + AwesomeDialog( + context: context, + dialogType: DialogType.error, + title: 'Fehler', + desc: 'Der Eintrag konnte nicht gespeichert werden', + ).show(); + } }, child: const Text('Speichern'), ), From c480f83f6d8b98b5d6e7185b9a0f6c4bdcc26d60 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 20:20:17 +0100 Subject: [PATCH 6/8] outsource todoicon --- lib/pages/main_page.dart | 20 ++------------------ lib/widgets/todo_icon.dart | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 lib/widgets/todo_icon.dart diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 82b4990..ce6a1ff 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -5,6 +5,8 @@ import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart'; +import '../widgets/todo_icon.dart'; + class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @@ -54,21 +56,3 @@ class MyHomePageState extends State { ); } } - -class MyToDoIcon extends StatelessWidget { - final Icon _icon; - const MyToDoIcon(this._icon, {super.key}); - - @override - Widget build(BuildContext context) { - return Stack(children: [ - _icon, - const Positioned( - // draw a red marble - top: 0.0, - right: 0.0, - child: Icon(Icons.brightness_1, size: 10.0, color: Colors.redAccent), - ) - ]); - } -} diff --git a/lib/widgets/todo_icon.dart b/lib/widgets/todo_icon.dart new file mode 100644 index 0000000..e5c82b6 --- /dev/null +++ b/lib/widgets/todo_icon.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; + +class MyToDoIcon extends StatelessWidget { + final Icon _icon; + const MyToDoIcon(this._icon, {super.key}); + + @override + Widget build(BuildContext context) { + return Stack(children: [ + _icon, + const Positioned( + // draw a red marble + top: 0.0, + right: 0.0, + child: Icon(Icons.brightness_1, size: 10.0, color: Colors.redAccent), + ) + ]); + } +} From 7689de73ac39342c1c9fc7dae3bd4fd21acb7bb0 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 20:33:44 +0100 Subject: [PATCH 7/8] Refactor wrong method name --- lib/providers/tasks_provider.dart | 2 +- lib/widgets/mood_form.dart | 2 +- lib/widgets/relapse_form.dart | 2 +- lib/widgets/sleep_form.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/providers/tasks_provider.dart b/lib/providers/tasks_provider.dart index 8ae2a04..f7cd673 100644 --- a/lib/providers/tasks_provider.dart +++ b/lib/providers/tasks_provider.dart @@ -19,7 +19,7 @@ class TasksProvider extends ChangeNotifier { initTasks(); } - void setTaksDone(Pages taskName) { + void setTaskDone(Pages taskName) { tasks[taskName] = false; notifyListeners(); } diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index 4661678..e43e97d 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -33,7 +33,7 @@ class MoodForm extends StatelessWidget { ), SubmitFormButton( submitCallback: inputModel.saveMood, - updateTasks: () => tasksModel.setTaksDone(Pages.mood), + updateTasks: () => tasksModel.setTaskDone(Pages.mood), ) ], ); diff --git a/lib/widgets/relapse_form.dart b/lib/widgets/relapse_form.dart index 38d3492..9451277 100644 --- a/lib/widgets/relapse_form.dart +++ b/lib/widgets/relapse_form.dart @@ -33,7 +33,7 @@ class RelapseForm extends StatelessWidget { ), SubmitFormButton( submitCallback: inputModel.saveRelapse, - updateTasks: () => tasksModel.setTaksDone(Pages.mood), + updateTasks: () => tasksModel.setTaskDone(Pages.mood), ) ], ); diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index b578e2c..ad033ba 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -47,7 +47,7 @@ class SleepForm extends StatelessWidget { ), SubmitFormButton( submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey), - updateTasks: () => tasksModel.setTaksDone(Pages.mood), + updateTasks: () => tasksModel.setTaskDone(Pages.mood), ) ], ); From afe481305c11121062b8b7dd9afd5db1f6fe0778 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 20:35:20 +0100 Subject: [PATCH 8/8] Add TaskProvider to Workout --- lib/widgets/workout_timer_widget.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/widgets/workout_timer_widget.dart b/lib/widgets/workout_timer_widget.dart index 59f67d4..a85a09e 100644 --- a/lib/widgets/workout_timer_widget.dart +++ b/lib/widgets/workout_timer_widget.dart @@ -2,7 +2,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/providers/workout_provider.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/widgets/timer_widget.dart'; import '../providers/timer_provider.dart'; @@ -15,6 +17,7 @@ class WorkoutTimerWidget extends StatelessWidget { Widget build(BuildContext context) { TimerProvider timerProvider = context.watch(); WorkoutProvider workoutProvider = context.watch(); + TasksProvider tasksProvider = context.read(); if (workoutProvider.isPhaseComplete && !workoutProvider.isWorkoutComplete) { Timer(const Duration(milliseconds: 1), () => workoutProvider.nextPhase()); @@ -26,6 +29,7 @@ class WorkoutTimerWidget extends StatelessWidget { () => showMotivationPopup(context, (double value) { workoutProvider.motivationAfter = value.toInt(); workoutProvider.saveWorkout(); + tasksProvider.setTaskDone(Pages.timer); }, 'Motivation nach dem Training')); }