import 'package:awesome_dialog/awesome_dialog.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/providers/page_provider.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart'; import '../widgets/todo_icon.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override MyHomePageState createState() => MyHomePageState(); } class MyHomePageState extends State { int _selectedIndex = 4; bool _isConfigured = false; void _onItemTapped(int index) { PageProvider pageProvider = context.read(); setState(() { if (_isConfigured) { pageProvider.showForm = false; _selectedIndex = index; return; } AwesomeDialog( context: context, dialogType: DialogType.info, title: 'Fehlende Konfiguration', desc: 'Bitte QR Code Scannen!', ).show(); }); } @override Widget build(BuildContext context) { var settingsProvider = context.watch(); var tasksProvider = context.watch(); PageProvider pageProvider = context.watch(); _isConfigured = settingsProvider.initialized; return Scaffold( appBar: AppBar( title: Row( children: [ Stack( children: [ const SizedBox( width: 70, ), if (pageProvider.showForm) IconButton( icon: const Icon(Icons.arrow_back, color: Colors.white), onPressed: pageProvider.swap), ], ), Text( '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsProvider.settings?.group}" : ""}') ], )), body: pages.values.elementAt(_selectedIndex)['page'], bottomNavigationBar: NavigationBar( onDestinationSelected: _onItemTapped, selectedIndex: _selectedIndex, destinations: pages.keys.map((key) { return NavigationDestination( icon: tasksProvider.tasks[key] ?? false ? MyToDoIcon(pages[key]?['icon']) : pages[key]!['icon'], label: pages[key]?['title']); }).toList()), ); } }