Added central user credentials management
This commit is contained in:
@ -4,10 +4,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'model/accountData.dart';
|
||||
import 'model/accountModel.dart';
|
||||
import 'model/chatList/chatListProps.dart';
|
||||
import 'model/chatList/chatProps.dart';
|
||||
@ -18,7 +18,7 @@ import 'storage/base/settingsProvider.dart';
|
||||
import 'theming/darkAppTheme.dart';
|
||||
import 'theming/lightAppTheme.dart';
|
||||
import 'view/login/login.dart';
|
||||
import 'widget/errorView.dart';
|
||||
import 'widget/placeholderView.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@ -27,7 +27,7 @@ Future<void> main() async {
|
||||
SecurityContext.defaultContext.setTrustedCertificatesBytes(data.buffer.asUint8List());
|
||||
|
||||
ErrorWidget.builder = (error) {
|
||||
return ErrorView(icon: Icons.phonelink_erase_rounded, text: error.toString());
|
||||
return PlaceholderView(icon: Icons.phonelink_erase_rounded, text: error.toString());
|
||||
};
|
||||
|
||||
runApp(
|
||||
@ -56,66 +56,54 @@ class Main extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MainState extends State<Main> {
|
||||
|
||||
final Future<SharedPreferences> _storage = SharedPreferences.getInstance();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Jiffy.setLocale("de");
|
||||
_storage.then((SharedPreferences preferences) => preferences.getBool("loggedIn") ?? false).then((value) => {
|
||||
if(value) {
|
||||
Provider.of<AccountModel>(context, listen: false).login()
|
||||
} else {
|
||||
Provider.of<AccountModel>(context, listen: false).logout()
|
||||
}
|
||||
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
||||
|
||||
AccountData().waitForPopulation().then((value) {
|
||||
Provider.of<AccountModel>(context, listen: false)
|
||||
.setState(value ? AccountModelState.loggedIn : AccountModelState.loggedOut);
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
|
||||
return Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Consumer<SettingsProvider>(
|
||||
builder: (context, settings, child) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: const [
|
||||
...GlobalMaterialLocalizations.delegates,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [
|
||||
Locale('de'),
|
||||
Locale('en'),
|
||||
],
|
||||
locale: const Locale('de'),
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: const [
|
||||
...GlobalMaterialLocalizations.delegates,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [
|
||||
Locale('de'),
|
||||
Locale('en'),
|
||||
],
|
||||
locale: const Locale('de'),
|
||||
|
||||
title: 'Marianum Fulda',
|
||||
|
||||
themeMode: settings.val().appTheme,
|
||||
theme: LightAppTheme.theme,
|
||||
darkTheme: DarkAppTheme.theme,
|
||||
|
||||
|
||||
title: 'Marianum Fulda',
|
||||
|
||||
themeMode: settings.val().appTheme,
|
||||
theme: LightAppTheme.theme,
|
||||
darkTheme: DarkAppTheme.theme,
|
||||
|
||||
|
||||
home: FutureBuilder<SharedPreferences>(
|
||||
future: _storage,
|
||||
builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
|
||||
|
||||
if(snapshot.hasData) {
|
||||
return Consumer<AccountModel>(
|
||||
builder: (context, accountModel, child) {
|
||||
return accountModel.isLoggedIn ? const App() : const Login();
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
)
|
||||
home: Consumer<AccountModel>(
|
||||
builder: (context, accountModel, child) {
|
||||
switch(accountModel.state) {
|
||||
case AccountModelState.loggedIn: return const App();
|
||||
case AccountModelState.loggedOut: return const Login();
|
||||
case AccountModelState.undefined: return const PlaceholderView(icon: Icons.timer, text: "Daten werden geladen");
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user