From 01d62a291c7929846b0fea08bddadf4e264e7ae6 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 14:57:56 +0100 Subject: [PATCH] refactoring mainpage --- lib/pages/main_page.dart | 59 +++++++----------------------------- lib/pages/pages_service.dart | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+), 48 deletions(-) create mode 100644 lib/pages/pages_service.dart diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 2e6a9f8..5a2af86 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -1,12 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:smoke_cess_app/pages/mood_page.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/pages/pages_service.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'; class MyHomePage extends StatefulWidget { @@ -20,21 +15,6 @@ class MyHomePageState extends State { int _selectedIndex = 4; bool _isConfigured = false; - final List _titles = [ - 'Stimmung', - 'Schlaf', - 'Timer', - 'Rückfall', - 'Scanner' - ]; - static const List _widgetOptions = [ - MoodPage(), - SleepPage(), - IntervalTimerPage(), - RelapsePage(), - ScannerPage(), - ]; - void _onItemTapped(int index) { setState(() { _isConfigured @@ -58,34 +38,17 @@ class MyHomePageState extends State { return Scaffold( appBar: AppBar( title: Text( - '${_titles[_selectedIndex]} ${_isConfigured ? "Gruppe $group" : ""}')), - body: _widgetOptions.elementAt(_selectedIndex), + '${pages.keys.elementAt(_selectedIndex)} ${_isConfigured ? "Gruppe $group" : ""}')), + body: pages.values.elementAt(_selectedIndex)['page'], bottomNavigationBar: NavigationBar( - onDestinationSelected: _onItemTapped, - selectedIndex: _selectedIndex, - destinations: const [ - NavigationDestination( - icon: Icon(Icons.mood_outlined, color: Colors.black), - label: 'Stimmung'), - NavigationDestination( - icon: Icon(Icons.bedtime_outlined, color: Colors.black), - 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, - ), + onDestinationSelected: _onItemTapped, + selectedIndex: _selectedIndex, + destinations: pages.keys.map((key) { + return NavigationDestination( + icon: pages[key]!['icon'] ?? + const Icon(Icons.disabled_by_default), + label: key); + }).toList()), ); } } diff --git a/lib/pages/pages_service.dart b/lib/pages/pages_service.dart new file mode 100644 index 0000000..e530550 --- /dev/null +++ b/lib/pages/pages_service.dart @@ -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) + }, +};