cpd_2022_zi/lib/pages/main_page.dart

75 lines
2.3 KiB
Dart

import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/material.dart';
import 'package:provider/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';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
MyHomePageState createState() => MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 4;
bool _isConfigured = false;
void _onItemTapped(int index) {
setState(() {
_isConfigured
? _selectedIndex = index
: AwesomeDialog(
context: context,
dialogType: DialogType.info,
title: 'Fehlende Konfiguration',
desc: 'Bitte QR Code Scannen!',
).show();
});
}
@override
Widget build(BuildContext context) {
var settingsModel = context.watch<SettingsProvider>();
var tasksModel = context.watch<TasksProvider>();
_isConfigured = settingsModel.initialized;
return Scaffold(
appBar: AppBar(
title: Text(
'${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')),
body: Center(
child: SingleChildScrollView(
child: pages.values.elementAt(_selectedIndex)['page'])),
bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped,
selectedIndex: _selectedIndex,
destinations: pages.keys.map((key) {
return NavigationDestination(
icon: tasksModel.tasks[key] ?? false
? MyToDoIcon(pages[key]?['icon'])
: pages[key]!['icon'],
label: pages[key]?['title']);
}).toList()),
);
}
}
class MyToDoIcon extends StatelessWidget {
final Icon _icon;
const MyToDoIcon(this._icon, {super.key});
@override
Widget build(BuildContext context) {
return Stack(children: <Widget>[
_icon,
const Positioned(
// draw a red marble
top: 0.0,
right: 0.0,
child: Icon(Icons.brightness_1, size: 10.0, color: Colors.redAccent),
)
]);
}
}