cpd_2022_zi/lib/pages/main_page.dart

75 lines
2.3 KiB
Dart
Raw Normal View History

2023-02-27 20:02:15 +01:00
import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/material.dart';
2023-02-27 02:27:42 +01:00
import 'package:provider/provider.dart';
2023-03-02 19:31:47 +01:00
import 'package:smoke_cess_app/providers/tasks_provider.dart';
2023-02-27 17:27:01 +01:00
import 'package:smoke_cess_app/services/pages_service.dart';
2023-02-27 02:27:42 +01:00
import 'package:smoke_cess_app/providers/settings_provider.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
2023-02-27 20:02:15 +01:00
: AwesomeDialog(
2023-02-17 13:47:52 +01:00
context: context,
2023-02-27 20:02:15 +01:00
dialogType: DialogType.info,
title: 'Fehlende Konfiguration',
desc: 'Bitte QR Code Scannen!',
).show();
2023-02-17 13:47:52 +01:00
});
}
@override
Widget build(BuildContext context) {
var settingsModel = context.watch<SettingsProvider>();
2023-03-02 19:31:47 +01:00
var tasksModel = context.watch<TasksProvider>();
_isConfigured = settingsModel.initialized;
return Scaffold(
appBar: AppBar(
title: Text(
2023-03-02 19:32:13 +01:00
'${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.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(
2023-03-02 19:31:47 +01:00
icon: tasksModel.tasks[key] ?? false
? MyToDoIcon(pages[key]?['icon'])
: pages[key]!['icon'],
2023-03-02 18:35:03 +01:00
label: pages[key]?['title']);
2023-02-27 14:57:56 +01:00
}).toList()),
);
}
}
2023-03-02 19:31:47 +01:00
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),
)
]);
}
}