use dispose function of workout_provider to cleanup instead of high level provider
parent
9d26bdee60
commit
e22d918a92
|
@ -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,
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,7 +10,14 @@ class WorkoutForm extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: const [
|
children: const [
|
||||||
Align(
|
Align(
|
||||||
|
@ -16,6 +26,6 @@ class WorkoutForm extends StatelessWidget {
|
||||||
),
|
),
|
||||||
WorkoutTimerWidget()
|
WorkoutTimerWidget()
|
||||||
],
|
],
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue