refactoring mainpage

main
Kai Mannweiler 2023-02-27 14:57:56 +01:00
parent 95915e759b
commit 01d62a291c
2 changed files with 43 additions and 48 deletions

View File

@ -1,12 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smoke_cess_app/pages/mood_page.dart'; import 'package:smoke_cess_app/pages/pages_service.dart';
import 'package:smoke_cess_app/pages/relapse_page.dart';
import 'package:smoke_cess_app/pages/scanner_page.dart';
import 'package:smoke_cess_app/pages/sleep_page.dart';
import 'package:smoke_cess_app/pages/interval_page.dart';
import 'package:smoke_cess_app/providers/settings_provider.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart';
import 'package:smoke_cess_app/services/settings_service.dart';
import 'package:smoke_cess_app/widgets/missing_config_popup.dart'; import 'package:smoke_cess_app/widgets/missing_config_popup.dart';
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
@ -20,21 +15,6 @@ class MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 4; int _selectedIndex = 4;
bool _isConfigured = false; bool _isConfigured = false;
final List<String> _titles = [
'Stimmung',
'Schlaf',
'Timer',
'Rückfall',
'Scanner'
];
static const List<Widget> _widgetOptions = <Widget>[
MoodPage(),
SleepPage(),
IntervalTimerPage(),
RelapsePage(),
ScannerPage(),
];
void _onItemTapped(int index) { void _onItemTapped(int index) {
setState(() { setState(() {
_isConfigured _isConfigured
@ -58,34 +38,17 @@ class MyHomePageState extends State<MyHomePage> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
'${_titles[_selectedIndex]} ${_isConfigured ? "Gruppe $group" : ""}')), '${pages.keys.elementAt(_selectedIndex)} ${_isConfigured ? "Gruppe $group" : ""}')),
body: _widgetOptions.elementAt(_selectedIndex), body: pages.values.elementAt(_selectedIndex)['page'],
bottomNavigationBar: NavigationBar( bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped, onDestinationSelected: _onItemTapped,
selectedIndex: _selectedIndex, selectedIndex: _selectedIndex,
destinations: const <Widget>[ destinations: pages.keys.map((key) {
NavigationDestination( return NavigationDestination(
icon: Icon(Icons.mood_outlined, color: Colors.black), icon: pages[key]!['icon'] ??
label: 'Stimmung'), const Icon(Icons.disabled_by_default),
NavigationDestination( label: key);
icon: Icon(Icons.bedtime_outlined, color: Colors.black), }).toList()),
label: 'Schlaf'),
NavigationDestination(
icon: Icon(
Icons.timer_outlined,
color: Colors.black,
),
label: 'Timer'),
NavigationDestination(
icon: Icon(Icons.smoke_free_outlined, color: Colors.black),
label: 'Rückfall'),
NavigationDestination(
icon: Icon(Icons.camera_alt_outlined, color: Colors.black),
label: 'Settings'),
],
//onTap: _onItemTapped,
),
); );
} }
} }

View File

@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'interval_page.dart';
import 'mood_page.dart';
import 'relapse_page.dart';
import 'scanner_page.dart';
import 'sleep_page.dart';
const pages = {
'Stimmung': {
'page': MoodPage(),
'icon': Icon(Icons.mood_outlined, color: Colors.black)
},
'Schlaf': {
'page': SleepPage(),
'icon': Icon(Icons.bedtime_outlined, color: Colors.black)
},
'Timer': {
'page': IntervalTimerPage(),
'icon': Icon(Icons.smoke_free_outlined, color: Colors.black)
},
'Rückfall': {
'page': RelapsePage(),
'icon': Icon(
Icons.timer_outlined,
color: Colors.black,
)
},
'Scanner': {
'page': ScannerPage(),
'icon': Icon(Icons.camera_alt_outlined, color: Colors.black)
},
};