diff --git a/lib/main.dart b/lib/main.dart index e2d6e90..4a49cd4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,13 +2,11 @@ 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/tasks_provider.dart'; -import 'package:smoke_cess_app/providers/timer_provider.dart'; import 'package:smoke_cess_app/services/notification_service.dart'; import 'package:timezone/data/latest.dart' as tz; import 'globals.dart' as globals; import 'providers/page_provider.dart'; import 'providers/settings_provider.dart'; -import 'providers/workout_provider.dart'; void main() { // to ensure all the widgets are initialized. @@ -27,7 +25,6 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - TimerProvider timerProvider = TimerProvider(); return MultiProvider( providers: [ ChangeNotifierProvider(create: (context) => SettingsProvider()), @@ -39,9 +36,6 @@ class MyApp extends StatelessWidget { ChangeNotifierProvider( create: (context) => PageProvider(), ), - ChangeNotifierProvider(create: (context) => timerProvider), - ChangeNotifierProvider( - create: (context) => WorkoutProvider(timerProvider)), ], child: const MaterialApp( title: _title, diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 21049d2..10ff0ec 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/providers/page_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/providers/settings_provider.dart'; @@ -22,11 +21,9 @@ class MyHomePageState extends State { void _onItemTapped(int index) { PageProvider pageProvider = context.read(); - WorkoutProvider workoutProvider = context.read(); setState(() { if (_isConfigured) { pageProvider.showForm = false; - workoutProvider.interruptWorkout(); _selectedIndex = index; return; } diff --git a/lib/providers/workout_provider.dart b/lib/providers/workout_provider.dart index 98c3163..0cf3804 100644 --- a/lib/providers/workout_provider.dart +++ b/lib/providers/workout_provider.dart @@ -105,6 +105,12 @@ class WorkoutProvider extends ChangeNotifier { Workout(motivationBefore, motivationAfter, DateTime.now()); globals.databaseService.addWorkout(workout); } + + @override + void dispose() { + interruptWorkout(); + super.dispose(); + } } Map> _workoutPhaseSettings = { diff --git a/lib/widgets/view_form_page.dart b/lib/widgets/view_form_page.dart index a907cfb..aa52fd1 100644 --- a/lib/widgets/view_form_page.dart +++ b/lib/widgets/view_form_page.dart @@ -5,9 +5,6 @@ import 'package:smoke_cess_app/services/pages_service.dart'; import '../providers/input_provider.dart'; import '../providers/page_provider.dart'; import '../providers/tasks_provider.dart'; -import '../providers/timer_provider.dart'; -import '../services/date_service.dart'; -import 'timer_widget.dart'; class ViewFormPage extends StatelessWidget { final Widget form; @@ -17,14 +14,11 @@ class ViewFormPage extends StatelessWidget { {super.key, required this.form, required this.view, required this.page}); void showPopup(BuildContext context) async { - TimerProvider timerProvider = context.read(); - Duration duration = await getTimeTill(page); - timerProvider.startTimer(duration); AwesomeDialog( context: context, dialogType: DialogType.info, title: 'Bald erst wieder', - body: TimerWidget(duration: duration), + desc: 'hier kommt ein timer hin', ).show(); } diff --git a/lib/widgets/workout_form.dart b/lib/widgets/workout_form.dart index e06c4c2..a176cd0 100644 --- a/lib/widgets/workout_form.dart +++ b/lib/widgets/workout_form.dart @@ -1,4 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import '../providers/timer_provider.dart'; +import '../providers/workout_provider.dart'; import 'mute_button.dart'; import 'workout_timer_widget.dart'; @@ -7,15 +10,22 @@ class WorkoutForm extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Align( - alignment: Alignment.topLeft, - child: MuteButton(), - ), - WorkoutTimerWidget() - ], - ); + TimerProvider timerProvider = TimerProvider(); + return MultiProvider( + providers: [ + ChangeNotifierProvider(create: (context) => timerProvider), + ChangeNotifierProvider( + create: (context) => WorkoutProvider(timerProvider)), + ], + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Align( + alignment: Alignment.topLeft, + child: MuteButton(), + ), + WorkoutTimerWidget() + ], + )); } }