From 7dd1a748f21994ad10bf19ac6802eb5d606b45f4 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 15:00:48 +0100 Subject: [PATCH] Moved Provider to the top level --- lib/main.dart | 8 +++++++- lib/widgets/workout_form.dart | 28 ++++++++-------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d94ea15..4e6924d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,11 +2,13 @@ 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. @@ -25,6 +27,7 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { + TimerProvider timerProvider = TimerProvider(); return MaterialApp( title: _title, home: MultiProvider( @@ -37,7 +40,10 @@ class MyApp extends StatelessWidget { ), ChangeNotifierProvider( create: (context) => PageProvider(), - ) + ), + ChangeNotifierProvider(create: (context) => timerProvider), + ChangeNotifierProvider( + create: (context) => WorkoutProvider(timerProvider)), ], child: const MyHomePage(), )); diff --git a/lib/widgets/workout_form.dart b/lib/widgets/workout_form.dart index 980c51a..e06c4c2 100644 --- a/lib/widgets/workout_form.dart +++ b/lib/widgets/workout_form.dart @@ -1,8 +1,4 @@ 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'; @@ -11,23 +7,15 @@ class WorkoutForm extends StatelessWidget { @override Widget build(BuildContext context) { - TimerProvider timerProvider = TimerProvider(); - return MultiProvider( - providers: [ - ChangeNotifierProvider(create: (context) => timerProvider), - ChangeNotifierProvider( - create: (context) => WorkoutProvider(timerProvider)), + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Align( + alignment: Alignment.topLeft, + child: MuteButton(), + ), + WorkoutTimerWidget() ], - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Align( - alignment: Alignment.topLeft, - child: MuteButton(), - ), - WorkoutTimerWidget() - ], - ), ); } }