Moved Provider to the top level

main
Kai Mannweiler 2023-03-03 15:00:48 +01:00
parent 4b1eb20ca1
commit 7dd1a748f2
2 changed files with 15 additions and 21 deletions

View File

@ -2,11 +2,13 @@ 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.
@ -25,6 +27,7 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TimerProvider timerProvider = TimerProvider();
return MaterialApp( return MaterialApp(
title: _title, title: _title,
home: MultiProvider( home: MultiProvider(
@ -37,7 +40,10 @@ class MyApp extends StatelessWidget {
), ),
ChangeNotifierProvider( ChangeNotifierProvider(
create: (context) => PageProvider(), create: (context) => PageProvider(),
) ),
ChangeNotifierProvider(create: (context) => timerProvider),
ChangeNotifierProvider(
create: (context) => WorkoutProvider(timerProvider)),
], ],
child: const MyHomePage(), child: const MyHomePage(),
)); ));

View File

@ -1,8 +1,4 @@
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';
@ -11,14 +7,7 @@ class WorkoutForm extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TimerProvider timerProvider = TimerProvider(); return Column(
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(
@ -27,7 +16,6 @@ class WorkoutForm extends StatelessWidget {
), ),
WorkoutTimerWidget() WorkoutTimerWidget()
], ],
),
); );
} }
} }