cpd_2022_zi/lib/pages/main_page.dart

57 lines
1.8 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2023-02-27 02:27:42 +01:00
import 'package:provider/provider.dart';
2023-02-27 14:57:56 +01:00
import 'package:smoke_cess_app/pages/pages_service.dart';
2023-02-27 02:27:42 +01:00
import 'package:smoke_cess_app/providers/settings_provider.dart';
2023-02-17 13:47:52 +01:00
import 'package:smoke_cess_app/widgets/missing_config_popup.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
2023-02-14 14:13:32 +01:00
MyHomePageState createState() => MyHomePageState();
}
2023-02-14 14:13:32 +01:00
class MyHomePageState extends State<MyHomePage> {
2023-02-26 17:07:38 +01:00
int _selectedIndex = 4;
bool _isConfigured = false;
2023-02-17 13:47:52 +01:00
void _onItemTapped(int index) {
setState(() {
_isConfigured
2023-02-17 13:47:52 +01:00
? _selectedIndex = index
: showDialog(
context: context,
builder: (BuildContext context) {
2023-02-20 19:32:23 +01:00
return const MissingConfigPopup(
title: 'Fehlende Konfiguration',
text: 'Bitte QR Code Scannen!',
);
2023-02-17 13:47:52 +01:00
});
});
}
@override
Widget build(BuildContext context) {
var settingsModel = context.watch<SettingsProvider>();
var group = settingsModel.settings?.group;
_isConfigured = settingsModel.initialized;
return Scaffold(
appBar: AppBar(
title: Text(
2023-02-27 14:57:56 +01:00
'${pages.keys.elementAt(_selectedIndex)} ${_isConfigured ? "Gruppe $group" : ""}')),
2023-02-27 19:34:11 +01:00
body: Center(
child: SingleChildScrollView(
child: pages.values.elementAt(_selectedIndex)['page'])),
bottomNavigationBar: NavigationBar(
2023-02-27 14:57:56 +01:00
onDestinationSelected: _onItemTapped,
selectedIndex: _selectedIndex,
destinations: pages.keys.map((key) {
return NavigationDestination(
icon: pages[key]!['icon'] ??
const Icon(Icons.disabled_by_default),
label: key);
}).toList()),
);
}
}