From 95915e759bd008638c54942f9e6875eba604a2a2 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 11:57:55 +0100 Subject: [PATCH] Start Refactoring mainpage using Settingsprovider --- lib/pages/main_page.dart | 13 +++++++------ lib/widgets/relapse_form.dart | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 739f0d1..2e6a9f8 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -18,7 +18,7 @@ class MyHomePage extends StatefulWidget { class MyHomePageState extends State { int _selectedIndex = 4; - int? _gruppe; + bool _isConfigured = false; final List _titles = [ 'Stimmung', @@ -35,11 +35,9 @@ class MyHomePageState extends State { ScannerPage(), ]; - Future _onItemTapped(int index) async { - _gruppe = await getGroup(); - bool isConfigured = _gruppe != null; + void _onItemTapped(int index) { setState(() { - isConfigured + _isConfigured ? _selectedIndex = index : showDialog( context: context, @@ -54,10 +52,13 @@ class MyHomePageState extends State { @override Widget build(BuildContext context) { + var settingsModel = context.watch(); + var group = settingsModel.settings?.group; + _isConfigured = settingsModel.initialized; return Scaffold( appBar: AppBar( title: Text( - '${_titles[_selectedIndex]} ${_gruppe != null ? "Gruppe $_gruppe" : ""}')), + '${_titles[_selectedIndex]} ${_isConfigured ? "Gruppe $group" : ""}')), body: _widgetOptions.elementAt(_selectedIndex), bottomNavigationBar: NavigationBar( onDestinationSelected: _onItemTapped, diff --git a/lib/widgets/relapse_form.dart b/lib/widgets/relapse_form.dart index cc53a53..a00ab31 100644 --- a/lib/widgets/relapse_form.dart +++ b/lib/widgets/relapse_form.dart @@ -13,13 +13,13 @@ class RelapseForm extends StatelessWidget { @override Widget build(BuildContext context) { var inputModel = context.watch(); - var settings = context.watch(); + var settingsModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedCard( title: 'Rückfallkategorie', - child: DropDown(settings.settings?.relapseCategories ?? []), + child: DropDown(settingsModel.settings?.relapseCategories ?? []), ), const ElevatedCard( title: 'Beschreibe deinen Rückfall',