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:provider/provider.dart';
import 'package:smoke_cess_app/pages/main_page.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/tasks_provider.dart';
import 'package:smoke_cess_app/providers/timer_provider.dart';
import 'package:smoke_cess_app/services/notification_service.dart'; import 'package:smoke_cess_app/services/notification_service.dart';
import 'package:timezone/data/latest.dart' as tz; import 'package:timezone/data/latest.dart' as tz;
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'providers/page_provider.dart'; import 'providers/page_provider.dart';
import 'providers/settings_provider.dart'; import 'providers/settings_provider.dart';
import 'providers/workout_provider.dart';
void main() { void main() {
// to ensure all the widgets are initialized. // to ensure all the widgets are initialized.
@ -27,7 +25,6 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TimerProvider timerProvider = TimerProvider();
return MultiProvider( return MultiProvider(
providers: [ providers: [
ChangeNotifierProvider(create: (context) => SettingsProvider()), ChangeNotifierProvider(create: (context) => SettingsProvider()),
@ -39,9 +36,6 @@ class MyApp extends StatelessWidget {
ChangeNotifierProvider( ChangeNotifierProvider(
create: (context) => PageProvider(), create: (context) => PageProvider(),
), ),
ChangeNotifierProvider(create: (context) => timerProvider),
ChangeNotifierProvider(
create: (context) => WorkoutProvider(timerProvider)),
], ],
child: const MaterialApp( child: const MaterialApp(
title: _title, title: _title,

View File

@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/page_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/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/services/pages_service.dart';
import 'package:smoke_cess_app/providers/settings_provider.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart';
@ -22,11 +21,9 @@ class MyHomePageState extends State<MyHomePage> {
void _onItemTapped(int index) { void _onItemTapped(int index) {
PageProvider pageProvider = context.read<PageProvider>(); PageProvider pageProvider = context.read<PageProvider>();
WorkoutProvider workoutProvider = context.read<WorkoutProvider>();
setState(() { setState(() {
if (_isConfigured) { if (_isConfigured) {
pageProvider.showForm = false; pageProvider.showForm = false;
workoutProvider.interruptWorkout();
_selectedIndex = index; _selectedIndex = index;
return; return;
} }

View File

@ -105,6 +105,12 @@ class WorkoutProvider extends ChangeNotifier {
Workout(motivationBefore, motivationAfter, DateTime.now()); Workout(motivationBefore, motivationAfter, DateTime.now());
globals.databaseService.addWorkout(workout); globals.databaseService.addWorkout(workout);
} }
@override
void dispose() {
interruptWorkout();
super.dispose();
}
} }
Map<String, Map<String, dynamic>> _workoutPhaseSettings = { 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/input_provider.dart';
import '../providers/page_provider.dart'; import '../providers/page_provider.dart';
import '../providers/tasks_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 { class ViewFormPage extends StatelessWidget {
final Widget form; final Widget form;
@ -17,14 +14,11 @@ class ViewFormPage extends StatelessWidget {
{super.key, required this.form, required this.view, required this.page}); {super.key, required this.form, required this.view, required this.page});
void showPopup(BuildContext context) async { void showPopup(BuildContext context) async {
TimerProvider timerProvider = context.read<TimerProvider>();
Duration duration = await getTimeTill(page);
timerProvider.startTimer(duration);
AwesomeDialog( AwesomeDialog(
context: context, context: context,
dialogType: DialogType.info, dialogType: DialogType.info,
title: 'Bald erst wieder', title: 'Bald erst wieder',
body: TimerWidget(duration: duration), desc: 'hier kommt ein timer hin',
).show(); ).show();
} }

View File

@ -1,4 +1,7 @@
import 'package:flutter/material.dart'; 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 'mute_button.dart';
import 'workout_timer_widget.dart'; import 'workout_timer_widget.dart';
@ -7,15 +10,22 @@ class WorkoutForm extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( TimerProvider timerProvider = TimerProvider();
mainAxisAlignment: MainAxisAlignment.center, return MultiProvider(
children: const [ providers: [
Align( ChangeNotifierProvider(create: (context) => timerProvider),
alignment: Alignment.topLeft, ChangeNotifierProvider(
child: MuteButton(), create: (context) => WorkoutProvider(timerProvider)),
), ],
WorkoutTimerWidget() child: Column(
], mainAxisAlignment: MainAxisAlignment.center,
); children: const [
Align(
alignment: Alignment.topLeft,
child: MuteButton(),
),
WorkoutTimerWidget()
],
));
} }
} }