From ccf34c07e83bde996f5fb8c5defd02e603f9c03a Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 13:13:33 +0100 Subject: [PATCH] Fixed Bug when swapping pages --- lib/main.dart | 4 ++++ lib/pages/main_page.dart | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index c5a19b7..d94ea15 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:smoke_cess_app/providers/tasks_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'; void main() { @@ -34,6 +35,9 @@ class MyApp extends StatelessWidget { update: (context, value, TasksProvider? previous) => TasksProvider(value), ), + ChangeNotifierProvider( + create: (context) => PageProvider(), + ) ], child: const MyHomePage(), )); diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 338dd75..1caf126 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -20,15 +20,19 @@ class MyHomePageState extends State { bool _isConfigured = false; void _onItemTapped(int index) { + PageProvider pageProvider = context.watch(); setState(() { - _isConfigured - ? _selectedIndex = index - : AwesomeDialog( - context: context, - dialogType: DialogType.info, - title: 'Fehlende Konfiguration', - desc: 'Bitte QR Code Scannen!', - ).show(); + if (_isConfigured) { + pageProvider.showForm = false; + _selectedIndex = index; + return; + } + AwesomeDialog( + context: context, + dialogType: DialogType.info, + title: 'Fehlende Konfiguration', + desc: 'Bitte QR Code Scannen!', + ).show(); }); } @@ -42,10 +46,8 @@ class MyHomePageState extends State { title: Text( '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), body: SingleChildScrollView( - child: ChangeNotifierProvider( - create: (context) => PageProvider(), child: pages.values.elementAt(_selectedIndex)['page'], - )), + ), bottomNavigationBar: NavigationBar( onDestinationSelected: _onItemTapped, selectedIndex: _selectedIndex,