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';
|
import '../widgets/todo_icon.dart';
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatelessWidget {
|
||||||
const MyHomePage({super.key});
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var settingsProvider = context.watch<SettingsProvider>();
|
SettingsProvider settingsProvider = context.watch<SettingsProvider>();
|
||||||
var tasksProvider = context.watch<TasksProvider>();
|
TasksProvider tasksProvider = context.watch<TasksProvider>();
|
||||||
PageProvider pageProvider = context.watch<PageProvider>();
|
PageProvider pageProvider = context.watch<PageProvider>();
|
||||||
|
bool isConfigured = settingsProvider.initialized;
|
||||||
|
|
||||||
_isConfigured = settingsProvider.initialized;
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Row(
|
title: Row(
|
||||||
|
@ -59,13 +34,20 @@ class MyHomePageState extends State<MyHomePage> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Text(
|
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(
|
bottomNavigationBar: NavigationBar(
|
||||||
onDestinationSelected: _onItemTapped,
|
onDestinationSelected: isConfigured
|
||||||
selectedIndex: _selectedIndex,
|
? 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) {
|
destinations: pages.keys.map((key) {
|
||||||
return NavigationDestination(
|
return NavigationDestination(
|
||||||
icon: tasksProvider.tasks[key] ?? false
|
icon: tasksProvider.tasks[key] ?? false
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||||
|
|
||||||
class PageProvider extends ChangeNotifier {
|
class PageProvider extends ChangeNotifier {
|
||||||
bool showForm = false;
|
bool showForm = false;
|
||||||
|
Pages _currentPage = Pages.settings;
|
||||||
|
|
||||||
void swap() {
|
void swap() {
|
||||||
showForm = !showForm;
|
showForm = !showForm;
|
||||||
notifyListeners();
|
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 {
|
enum Pages {
|
||||||
mood,
|
mood,
|
||||||
sleep,
|
sleep,
|
||||||
relapse,
|
|
||||||
timer,
|
timer,
|
||||||
|
relapse,
|
||||||
settings,
|
settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue