Fixed Bug when swapping pages

main
Kai Mannweiler 2023-03-03 13:13:33 +01:00
parent f62cdd2543
commit ccf34c07e8
2 changed files with 17 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import 'package:smoke_cess_app/providers/tasks_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/settings_provider.dart'; import 'providers/settings_provider.dart';
void main() { void main() {
@ -34,6 +35,9 @@ class MyApp extends StatelessWidget {
update: (context, value, TasksProvider? previous) => update: (context, value, TasksProvider? previous) =>
TasksProvider(value), TasksProvider(value),
), ),
ChangeNotifierProvider(
create: (context) => PageProvider(),
)
], ],
child: const MyHomePage(), child: const MyHomePage(),
)); ));

View File

@ -20,10 +20,14 @@ class MyHomePageState extends State<MyHomePage> {
bool _isConfigured = false; bool _isConfigured = false;
void _onItemTapped(int index) { void _onItemTapped(int index) {
PageProvider pageProvider = context.watch<PageProvider>();
setState(() { setState(() {
_isConfigured if (_isConfigured) {
? _selectedIndex = index pageProvider.showForm = false;
: AwesomeDialog( _selectedIndex = index;
return;
}
AwesomeDialog(
context: context, context: context,
dialogType: DialogType.info, dialogType: DialogType.info,
title: 'Fehlende Konfiguration', title: 'Fehlende Konfiguration',
@ -42,10 +46,8 @@ class MyHomePageState extends State<MyHomePage> {
title: Text( title: Text(
'${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')),
body: SingleChildScrollView( body: SingleChildScrollView(
child: ChangeNotifierProvider(
create: (context) => PageProvider(),
child: pages.values.elementAt(_selectedIndex)['page'], child: pages.values.elementAt(_selectedIndex)['page'],
)), ),
bottomNavigationBar: NavigationBar( bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped, onDestinationSelected: _onItemTapped,
selectedIndex: _selectedIndex, selectedIndex: _selectedIndex,