use dispose function of workout_provider to cleanup instead of high level provider

main
Kai Mannweiler 2023-03-03 17:19:58 +01:00
parent 9d26bdee60
commit e22d918a92
5 changed files with 27 additions and 26 deletions

View File

@ -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,

View File

@ -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<MyHomePage> {
void _onItemTapped(int index) {
PageProvider pageProvider = context.read<PageProvider>();
WorkoutProvider workoutProvider = context.read<WorkoutProvider>();
setState(() {
if (_isConfigured) {
pageProvider.showForm = false;
workoutProvider.interruptWorkout();
_selectedIndex = index;
return;
}

View File

@ -105,6 +105,12 @@ class WorkoutProvider extends ChangeNotifier {
Workout(motivationBefore, motivationAfter, DateTime.now());
globals.databaseService.addWorkout(workout);
}
@override
void dispose() {
interruptWorkout();
super.dispose();
}
}
Map<String, Map<String, dynamic>> _workoutPhaseSettings = {

View File

@ -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<TimerProvider>();
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();
}

View File

@ -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,7 +10,14 @@ class WorkoutForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
TimerProvider timerProvider = TimerProvider();
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => timerProvider),
ChangeNotifierProvider(
create: (context) => WorkoutProvider(timerProvider)),
],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Align(
@ -16,6 +26,6 @@ class WorkoutForm extends StatelessWidget {
),
WorkoutTimerWidget()
],
);
));
}
}