fix initial load bug
This commit is contained in:
parent
dae5182f90
commit
f9dbbf4638
@ -59,6 +59,7 @@ class SCNApp extends StatelessWidget {
|
|||||||
builder: (context, appTheme, child) => MaterialApp(
|
builder: (context, appTheme, child) => MaterialApp(
|
||||||
title: 'SimpleCloudNotifier',
|
title: 'SimpleCloudNotifier',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
|
//TODO color settings
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue, brightness: appTheme.darkMode ? Brightness.dark : Brightness.light),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue, brightness: appTheme.darkMode ? Brightness.dark : Brightness.light),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
|
@ -18,14 +18,6 @@ class SCNNavLayout extends StatefulWidget {
|
|||||||
class _SCNNavLayoutState extends State<SCNNavLayout> {
|
class _SCNNavLayoutState extends State<SCNNavLayout> {
|
||||||
int _selectedIndex = 0; // 4 == FAB
|
int _selectedIndex = 0; // 4 == FAB
|
||||||
|
|
||||||
static const List<Widget> _subPages = <Widget>[
|
|
||||||
MessageListPage(),
|
|
||||||
ChannelRootPage(),
|
|
||||||
AccountRootPage(),
|
|
||||||
SettingsRootPage(),
|
|
||||||
SendRootPage(),
|
|
||||||
];
|
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
void _onItemTapped(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
@ -47,7 +39,16 @@ class _SCNNavLayoutState extends State<SCNNavLayout> {
|
|||||||
showSearch: _selectedIndex == 0 || _selectedIndex == 1,
|
showSearch: _selectedIndex == 0 || _selectedIndex == 1,
|
||||||
showThemeSwitch: true,
|
showThemeSwitch: true,
|
||||||
),
|
),
|
||||||
body: _subPages.elementAt(_selectedIndex),
|
body: IndexedStack(
|
||||||
|
children: [
|
||||||
|
MessageListPage(),
|
||||||
|
ChannelRootPage(),
|
||||||
|
AccountRootPage(),
|
||||||
|
SettingsRootPage(),
|
||||||
|
SendRootPage(),
|
||||||
|
],
|
||||||
|
index: _selectedIndex,
|
||||||
|
),
|
||||||
bottomNavigationBar: _buildNavBar(context),
|
bottomNavigationBar: _buildNavBar(context),
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
||||||
floatingActionButton: _buildFAB(context),
|
floatingActionButton: _buildFAB(context),
|
||||||
@ -57,7 +58,6 @@ class _SCNNavLayoutState extends State<SCNNavLayout> {
|
|||||||
Widget _buildFAB(BuildContext context) {
|
Widget _buildFAB(BuildContext context) {
|
||||||
return FloatingActionButton(
|
return FloatingActionButton(
|
||||||
onPressed: _onFABTapped,
|
onPressed: _onFABTapped,
|
||||||
tooltip: 'Increment',
|
|
||||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(17))),
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(17))),
|
||||||
elevation: 2.0,
|
elevation: 2.0,
|
||||||
child: const Icon(FontAwesomeIcons.solidPaperPlaneTop),
|
child: const Icon(FontAwesomeIcons.solidPaperPlaneTop),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class Globals {
|
class Globals {
|
||||||
static final Globals _singleton = Globals._internal();
|
static final Globals _singleton = Globals._internal();
|
||||||
@ -18,6 +19,8 @@ class Globals {
|
|||||||
String platform = '';
|
String platform = '';
|
||||||
String hostname = '';
|
String hostname = '';
|
||||||
|
|
||||||
|
late SharedPreferences sharedPrefs;
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||||
|
|
||||||
@ -27,5 +30,7 @@ class Globals {
|
|||||||
this.buildNumber = packageInfo.buildNumber;
|
this.buildNumber = packageInfo.buildNumber;
|
||||||
this.platform = Platform.operatingSystem;
|
this.platform = Platform.operatingSystem;
|
||||||
this.hostname = Platform.localHostname;
|
this.hostname = Platform.localHostname;
|
||||||
|
|
||||||
|
this.sharedPrefs = await SharedPreferences.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||||
import 'package:simplecloudnotifier/models/key_token_auth.dart';
|
import 'package:simplecloudnotifier/models/key_token_auth.dart';
|
||||||
import 'package:simplecloudnotifier/models/user.dart';
|
import 'package:simplecloudnotifier/models/user.dart';
|
||||||
|
import 'package:simplecloudnotifier/state/globals.dart';
|
||||||
|
|
||||||
class UserAccount extends ChangeNotifier {
|
class UserAccount extends ChangeNotifier {
|
||||||
User? _user;
|
User? _user;
|
||||||
@ -37,11 +38,9 @@ class UserAccount extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void load() async {
|
void load() {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final uid = Globals().sharedPrefs.getString('auth.userid');
|
||||||
|
final tok = Globals().sharedPrefs.getString('auth.token');
|
||||||
final uid = prefs.getString('auth.userid');
|
|
||||||
final tok = prefs.getString('auth.token');
|
|
||||||
|
|
||||||
if (uid != null && tok != null) {
|
if (uid != null && tok != null) {
|
||||||
setToken(KeyTokenAuth(userId: uid, token: tok));
|
setToken(KeyTokenAuth(userId: uid, token: tok));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user