Start Refactoring mainpage using Settingsprovider

main
Kai Mannweiler 2023-02-27 11:57:55 +01:00
parent 395749618b
commit 95915e759b
2 changed files with 9 additions and 8 deletions

View File

@ -18,7 +18,7 @@ class MyHomePage extends StatefulWidget {
class MyHomePageState extends State<MyHomePage> { class MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 4; int _selectedIndex = 4;
int? _gruppe; bool _isConfigured = false;
final List<String> _titles = [ final List<String> _titles = [
'Stimmung', 'Stimmung',
@ -35,11 +35,9 @@ class MyHomePageState extends State<MyHomePage> {
ScannerPage(), ScannerPage(),
]; ];
Future<void> _onItemTapped(int index) async { void _onItemTapped(int index) {
_gruppe = await getGroup();
bool isConfigured = _gruppe != null;
setState(() { setState(() {
isConfigured _isConfigured
? _selectedIndex = index ? _selectedIndex = index
: showDialog( : showDialog(
context: context, context: context,
@ -54,10 +52,13 @@ class MyHomePageState extends State<MyHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var settingsModel = context.watch<SettingsProvider>();
var group = settingsModel.settings?.group;
_isConfigured = settingsModel.initialized;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
'${_titles[_selectedIndex]} ${_gruppe != null ? "Gruppe $_gruppe" : ""}')), '${_titles[_selectedIndex]} ${_isConfigured ? "Gruppe $group" : ""}')),
body: _widgetOptions.elementAt(_selectedIndex), body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: NavigationBar( bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped, onDestinationSelected: _onItemTapped,

View File

@ -13,13 +13,13 @@ class RelapseForm extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>(); var inputModel = context.watch<InputProvider>();
var settings = context.watch<SettingsProvider>(); var settingsModel = context.watch<SettingsProvider>();
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
ElevatedCard( ElevatedCard(
title: 'Rückfallkategorie', title: 'Rückfallkategorie',
child: DropDown(settings.settings?.relapseCategories ?? []), child: DropDown(settingsModel.settings?.relapseCategories ?? []),
), ),
const ElevatedCard( const ElevatedCard(
title: 'Beschreibe deinen Rückfall', title: 'Beschreibe deinen Rückfall',