main page stateless, extended pageprovider
parent
54ec18d1fe
commit
3d0c8d3724
|
@ -8,41 +8,16 @@ import 'package:smoke_cess_app/providers/settings_provider.dart';
|
|||
|
||||
import '../widgets/todo_icon.dart';
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
class MyHomePage extends StatelessWidget {
|
||||
const MyHomePage({super.key});
|
||||
|
||||
@override
|
||||
MyHomePageState createState() => MyHomePageState();
|
||||
}
|
||||
|
||||
class MyHomePageState extends State<MyHomePage> {
|
||||
int _selectedIndex = 4;
|
||||
bool _isConfigured = false;
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
PageProvider pageProvider = context.read<PageProvider>();
|
||||
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<SettingsProvider>();
|
||||
var tasksProvider = context.watch<TasksProvider>();
|
||||
SettingsProvider settingsProvider = context.watch<SettingsProvider>();
|
||||
TasksProvider tasksProvider = context.watch<TasksProvider>();
|
||||
PageProvider pageProvider = context.watch<PageProvider>();
|
||||
bool isConfigured = settingsProvider.initialized;
|
||||
|
||||
_isConfigured = settingsProvider.initialized;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
|
@ -59,13 +34,20 @@ class MyHomePageState extends State<MyHomePage> {
|
|||
],
|
||||
),
|
||||
Text(
|
||||
'${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsProvider.settings?.group}" : ""}')
|
||||
'${pageProvider.currentPageData['title']} ${isConfigured ? "Gruppe ${settingsProvider.settings?.group}" : ""}')
|
||||
],
|
||||
)),
|
||||
body: pages.values.elementAt(_selectedIndex)['page'],
|
||||
body: pageProvider.currentPageData['page'],
|
||||
bottomNavigationBar: NavigationBar(
|
||||
onDestinationSelected: _onItemTapped,
|
||||
selectedIndex: _selectedIndex,
|
||||
onDestinationSelected: isConfigured
|
||||
? pageProvider.currentPage
|
||||
: (value) => AwesomeDialog(
|
||||
context: context,
|
||||
dialogType: DialogType.info,
|
||||
title: 'Fehlende Konfiguration',
|
||||
desc: 'Bitte QR Code Scannen!',
|
||||
).show(),
|
||||
selectedIndex: pageProvider.currentPageIndex,
|
||||
destinations: pages.keys.map((key) {
|
||||
return NavigationDestination(
|
||||
icon: tasksProvider.tasks[key] ?? false
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||
|
||||
class PageProvider extends ChangeNotifier {
|
||||
bool showForm = false;
|
||||
Pages _currentPage = Pages.settings;
|
||||
|
||||
void swap() {
|
||||
showForm = !showForm;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Map<String, dynamic> get currentPageData => pages[_currentPage]!;
|
||||
|
||||
int get currentPageIndex => _currentPage.index;
|
||||
|
||||
void currentPage(int index) {
|
||||
showForm = false;
|
||||
_currentPage = Pages.values[index];
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import '../pages/sleep_page.dart';
|
|||
enum Pages {
|
||||
mood,
|
||||
sleep,
|
||||
relapse,
|
||||
timer,
|
||||
relapse,
|
||||
settings,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue