From f9dbbf4638923cc26d223ca04cd1ced3639ffd1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 26 May 2024 18:34:42 +0200 Subject: [PATCH] fix initial load bug --- flutter/lib/main.dart | 1 + flutter/lib/nav_layout.dart | 20 ++++++++++---------- flutter/lib/state/globals.dart | 5 +++++ flutter/lib/state/user_account.dart | 9 ++++----- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index d715741..68897e8 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -59,6 +59,7 @@ class SCNApp extends StatelessWidget { builder: (context, appTheme, child) => MaterialApp( title: 'SimpleCloudNotifier', theme: ThemeData( + //TODO color settings colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue, brightness: appTheme.darkMode ? Brightness.dark : Brightness.light), useMaterial3: true, ), diff --git a/flutter/lib/nav_layout.dart b/flutter/lib/nav_layout.dart index 967d1f5..778342c 100644 --- a/flutter/lib/nav_layout.dart +++ b/flutter/lib/nav_layout.dart @@ -18,14 +18,6 @@ class SCNNavLayout extends StatefulWidget { class _SCNNavLayoutState extends State { int _selectedIndex = 0; // 4 == FAB - static const List _subPages = [ - MessageListPage(), - ChannelRootPage(), - AccountRootPage(), - SettingsRootPage(), - SendRootPage(), - ]; - void _onItemTapped(int index) { setState(() { _selectedIndex = index; @@ -47,7 +39,16 @@ class _SCNNavLayoutState extends State { showSearch: _selectedIndex == 0 || _selectedIndex == 1, showThemeSwitch: true, ), - body: _subPages.elementAt(_selectedIndex), + body: IndexedStack( + children: [ + MessageListPage(), + ChannelRootPage(), + AccountRootPage(), + SettingsRootPage(), + SendRootPage(), + ], + index: _selectedIndex, + ), bottomNavigationBar: _buildNavBar(context), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: _buildFAB(context), @@ -57,7 +58,6 @@ class _SCNNavLayoutState extends State { Widget _buildFAB(BuildContext context) { return FloatingActionButton( onPressed: _onFABTapped, - tooltip: 'Increment', shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(17))), elevation: 2.0, child: const Icon(FontAwesomeIcons.solidPaperPlaneTop), diff --git a/flutter/lib/state/globals.dart b/flutter/lib/state/globals.dart index 8a3ffb8..583b190 100644 --- a/flutter/lib/state/globals.dart +++ b/flutter/lib/state/globals.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:package_info_plus/package_info_plus.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class Globals { static final Globals _singleton = Globals._internal(); @@ -18,6 +19,8 @@ class Globals { String platform = ''; String hostname = ''; + late SharedPreferences sharedPrefs; + Future init() async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); @@ -27,5 +30,7 @@ class Globals { this.buildNumber = packageInfo.buildNumber; this.platform = Platform.operatingSystem; this.hostname = Platform.localHostname; + + this.sharedPrefs = await SharedPreferences.getInstance(); } } diff --git a/flutter/lib/state/user_account.dart b/flutter/lib/state/user_account.dart index ce7b1c3..cf71ab4 100644 --- a/flutter/lib/state/user_account.dart +++ b/flutter/lib/state/user_account.dart @@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:simplecloudnotifier/api/api_client.dart'; import 'package:simplecloudnotifier/models/key_token_auth.dart'; import 'package:simplecloudnotifier/models/user.dart'; +import 'package:simplecloudnotifier/state/globals.dart'; class UserAccount extends ChangeNotifier { User? _user; @@ -37,11 +38,9 @@ class UserAccount extends ChangeNotifier { notifyListeners(); } - void load() async { - final prefs = await SharedPreferences.getInstance(); - - final uid = prefs.getString('auth.userid'); - final tok = prefs.getString('auth.token'); + void load() { + final uid = Globals().sharedPrefs.getString('auth.userid'); + final tok = Globals().sharedPrefs.getString('auth.token'); if (uid != null && tok != null) { setToken(KeyTokenAuth(userId: uid, token: tok));