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: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(),
));

View File

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