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> {
int _selectedIndex = 4;
int? _gruppe;
bool _isConfigured = false;
final List<String> _titles = [
'Stimmung',
@ -35,11 +35,9 @@ class MyHomePageState extends State<MyHomePage> {
ScannerPage(),
];
Future<void> _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<MyHomePage> {
@override
Widget build(BuildContext context) {
var settingsModel = context.watch<SettingsProvider>();
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,

View File

@ -13,13 +13,13 @@ class RelapseForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>();
var settings = context.watch<SettingsProvider>();
var settingsModel = context.watch<SettingsProvider>();
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',