diff --git a/lib/api/marianumcloud/autocomplete/autocompleteApi.dart b/lib/api/marianumcloud/autocomplete/autocompleteApi.dart index bc35f78..9040aef 100644 --- a/lib/api/marianumcloud/autocomplete/autocompleteApi.dart +++ b/lib/api/marianumcloud/autocomplete/autocompleteApi.dart @@ -3,13 +3,12 @@ import 'dart:io'; import 'package:http/http.dart' as http; import 'package:http/http.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import '../../../model/accountData.dart'; import 'autocompleteResponse.dart'; class AutocompleteApi { Future find(String query) async { - var preferences = await SharedPreferences.getInstance(); Map getParameters = { "search": query, "itemType": " ", @@ -22,7 +21,7 @@ class AutocompleteApi { headers.putIfAbsent("Accept", () => "application/json"); headers.putIfAbsent("OCS-APIRequest", () => "true"); - Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/core/autocomplete/get", getParameters); + Uri endpoint = Uri.https("${AccountData().buildHttpAuthString()}@cloud.marianum-fulda.de", "/ocs/v2.php/core/autocomplete/get", getParameters); Response response = await http.get(endpoint, headers: headers); if(response.statusCode != HttpStatus.ok) throw Exception("Api call failed with ${response.statusCode}: ${response.body}"); diff --git a/lib/api/marianumcloud/files-sharing/fileSharingApi.dart b/lib/api/marianumcloud/files-sharing/fileSharingApi.dart index 1ef1070..371bc34 100644 --- a/lib/api/marianumcloud/files-sharing/fileSharingApi.dart +++ b/lib/api/marianumcloud/files-sharing/fileSharingApi.dart @@ -3,19 +3,17 @@ import 'dart:io'; import 'package:http/http.dart' as http; import 'package:http/http.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import '../../../model/accountData.dart'; import 'fileSharingApiParams.dart'; class FileSharingApi { Future share(FileSharingApiParams query) async { - var preferences = await SharedPreferences.getInstance(); - Map headers = {}; headers.putIfAbsent("Accept", () => "application/json"); headers.putIfAbsent("OCS-APIRequest", () => "true"); - Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/files_sharing/api/v1/shares", query.toJson().map((key, value) => MapEntry(key, value.toString()))); + Uri endpoint = Uri.https("${AccountData().buildHttpAuthString()}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/files_sharing/api/v1/shares", query.toJson().map((key, value) => MapEntry(key, value.toString()))); log("request file share"); Response response = await http.post(endpoint, headers: headers); diff --git a/lib/api/marianumcloud/talk/talkApi.dart b/lib/api/marianumcloud/talk/talkApi.dart index 6e09927..8f7bb50 100644 --- a/lib/api/marianumcloud/talk/talkApi.dart +++ b/lib/api/marianumcloud/talk/talkApi.dart @@ -1,8 +1,8 @@ import 'dart:developer'; import 'package:http/http.dart' as http; -import 'package:shared_preferences/shared_preferences.dart'; +import '../../../model/accountData.dart'; import '../../apiError.dart'; import '../../apiParams.dart'; import '../../apiRequest.dart'; @@ -32,9 +32,7 @@ abstract class TalkApi extends ApiRequest { getParameters?.update(key, (value) => value.toString()); }); - SharedPreferences preferences = await SharedPreferences.getInstance(); - - Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/spreed/api/$path", getParameters); + Uri endpoint = Uri.https("${AccountData().buildHttpAuthString()}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/spreed/api/$path", getParameters); headers ??= {}; headers?.putIfAbsent("Accept", () => "application/json"); diff --git a/lib/api/marianumcloud/webdav/webdavApi.dart b/lib/api/marianumcloud/webdav/webdavApi.dart index 67c5723..f1d6a4e 100644 --- a/lib/api/marianumcloud/webdav/webdavApi.dart +++ b/lib/api/marianumcloud/webdav/webdavApi.dart @@ -1,6 +1,6 @@ import 'package:nextcloud/nextcloud.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import '../../../model/accountData.dart'; import '../../apiRequest.dart'; import '../../apiResponse.dart'; @@ -17,14 +17,10 @@ abstract class WebdavApi extends ApiRequest { static Future webdavConnectString = buildWebdavConnectString(); static Future establishWebdavConnection() async { - SharedPreferences preferences = await SharedPreferences.getInstance(); - - return NextcloudClient("https://cloud.marianum-fulda.de/", username: preferences.getString("username"), password: preferences.getString("password"), loginName: preferences.getString("username")).webdav; + return NextcloudClient("https://cloud.marianum-fulda.de/", username: AccountData().getUsername(), password: AccountData().getPassword(), loginName: AccountData().getUsername()).webdav; } static Future buildWebdavConnectString() async { - SharedPreferences preferences = await SharedPreferences.getInstance(); - - return "https://${preferences.getString("username")}:${preferences.getString("password")}@cloud.marianum-fulda.de/remote.php/dav/files/${preferences.getString("username")}/"; + return "https://${AccountData().buildHttpAuthString()}@cloud.marianum-fulda.de/remote.php/dav/files/${AccountData().getUsername()}/"; } } \ No newline at end of file diff --git a/lib/api/webuntis/queries/authenticate/authenticate.dart b/lib/api/webuntis/queries/authenticate/authenticate.dart index cdd5f2c..8915474 100644 --- a/lib/api/webuntis/queries/authenticate/authenticate.dart +++ b/lib/api/webuntis/queries/authenticate/authenticate.dart @@ -2,8 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:developer'; -import 'package:shared_preferences/shared_preferences.dart'; - +import '../../../../model/accountData.dart'; import '../../webuntisApi.dart'; import 'authenticateParams.dart'; import 'authenticateResponse.dart'; @@ -28,12 +27,10 @@ class Authenticate extends WebuntisApi { static AuthenticateResponse? _lastResponse; static Future createSession() async { - SharedPreferences preferences = await SharedPreferences.getInstance(); - _lastResponse = await Authenticate( AuthenticateParams( - user: preferences.getString("username")!, - password: preferences.getString("password")!, + user: AccountData().getUsername(), + password: AccountData().getPassword(), ) ).run(); } diff --git a/lib/app.dart b/lib/app.dart index 411170a..75eb558 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -22,14 +22,16 @@ class App extends StatefulWidget { class _AppState extends State { int currentPage = 0; late Timer refetchChats; + late Timer updateTimings; @override void initState() { - Timer.periodic(const Duration(seconds: 30), (Timer t) => setState((){})); - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { Provider.of(context, listen: false).run(); }); + + updateTimings = Timer.periodic(const Duration(seconds: 30), (Timer t) => setState((){})); + refetchChats = Timer.periodic(const Duration(minutes: 1), (timer) { if(!context.mounted) return; Provider.of(context, listen: false).run(); @@ -107,6 +109,7 @@ class _AppState extends State { @override void dispose() { refetchChats.cancel(); + updateTimings.cancel(); super.dispose(); } } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 1b7a957..6f3c23c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -27,7 +27,7 @@ Future 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
{ - - final Future _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(context, listen: false).login() - } else { - Provider.of(context, listen: false).logout() - } + + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); + + AccountData().waitForPopulation().then((value) { + Provider.of(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( 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( - future: _storage, - builder: (BuildContext context, AsyncSnapshot snapshot) { - - if(snapshot.hasData) { - return Consumer( - builder: (context, accountModel, child) { - return accountModel.isLoggedIn ? const App() : const Login(); - }, - ); - } else { - return const Center(child: CircularProgressIndicator()); - } - }, - ) + home: Consumer( + 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"); + } + }, + ), ); }, ), diff --git a/lib/model/accountData.dart b/lib/model/accountData.dart new file mode 100644 index 0000000..d18cd16 --- /dev/null +++ b/lib/model/accountData.dart @@ -0,0 +1,78 @@ +import 'dart:async'; + +import 'package:flutter/cupertino.dart'; +import 'package:provider/provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import 'accountModel.dart'; + +class AccountData { + static const _usernameField = "username"; + static const _passwordField = "password"; + + static final AccountData _instance = AccountData._construct(); + final Future _storage = SharedPreferences.getInstance(); + Completer _populated = Completer(); + + factory AccountData() { + return _instance; + } + + AccountData._construct() { + _updateFromStorage(); + } + + String? _username; + String? _password; + + String getUsername() { + if(_username == null) throw Exception("Username not initialized"); + return _username!; + } + + String getPassword() { + if(_password == null) throw Exception("Password not initialized"); + return _password!; + } + + Future setData(BuildContext context, String username, String password) async { + SharedPreferences storage = await _storage; + + storage.setString(_usernameField, username); + storage.setString(_passwordField, password); + await _updateFromStorage(); + } + + void removeData(BuildContext context) async { + _populated = Completer(); + Provider.of(context, listen: false).setState(AccountModelState.loggedOut); + + SharedPreferences storage = await _storage; + storage.remove(_usernameField); + storage.remove(_passwordField); + } + + Future _updateFromStorage() async { + SharedPreferences storage = await _storage; + await storage.reload(); + if(storage.containsKey(_usernameField) && storage.containsKey(_passwordField)) { + _username = storage.getString(_usernameField); + _password = storage.getString(_passwordField); + _populated.complete(); + } + } + + Future waitForPopulation() async { + await _populated.future; + return isPopulated(); + } + + bool isPopulated() { + return _username != null && _password != null; + } + + String buildHttpAuthString() { + if(!isPopulated()) throw Exception("AccountData (e.g. username or password) is not initialized!"); + return "$_username:$_password"; + } +} \ No newline at end of file diff --git a/lib/model/accountModel.dart b/lib/model/accountModel.dart index 1ffad5a..39df3f4 100644 --- a/lib/model/accountModel.dart +++ b/lib/model/accountModel.dart @@ -1,17 +1,17 @@ import 'package:flutter/cupertino.dart'; class AccountModel extends ChangeNotifier { - bool _isLoggedIn = false; + AccountModelState _accountState = AccountModelState.undefined; + AccountModelState get state => _accountState; - bool get isLoggedIn => _isLoggedIn; - - void logout() { - _isLoggedIn = false; + void setState(AccountModelState state) { + _accountState = state; notifyListeners(); } +} - void login() { - _isLoggedIn = true; - notifyListeners(); - } +enum AccountModelState { + undefined, + loggedIn, + loggedOut, } \ No newline at end of file diff --git a/lib/storage/base/settingsProvider.dart b/lib/storage/base/settingsProvider.dart index a1b934a..c347a00 100644 --- a/lib/storage/base/settingsProvider.dart +++ b/lib/storage/base/settingsProvider.dart @@ -1,9 +1,9 @@ import 'dart:convert'; import 'dart:developer'; import 'package:flutter/material.dart'; -import 'package:marianum_mobile/storage/file/fileSettings.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../file/fileSettings.dart'; import '../gradeAverages/gradeAveragesSettings.dart'; import '../talk/talkSettings.dart'; import '../timetable/timetableSettings.dart'; diff --git a/lib/view/login/login.dart b/lib/view/login/login.dart index 67a3bd4..d7280ed 100644 --- a/lib/view/login/login.dart +++ b/lib/view/login/login.dart @@ -1,15 +1,11 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; import 'package:flutter_login/flutter_login.dart'; import 'package:provider/provider.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import '../../api/apiError.dart'; import '../../api/webuntis/queries/authenticate/authenticateParams.dart'; import '../../api/webuntis/queries/authenticate/authenticate.dart'; -import '../../api/webuntis/webuntisError.dart'; +import '../../model/accountData.dart'; import '../../model/accountModel.dart'; class Login extends StatefulWidget { @@ -27,8 +23,7 @@ class _LoginState extends State { } Future _login(LoginData data) async { - SharedPreferences preferences = await SharedPreferences.getInstance(); - preferences.setBool("loggedIn", false); + AccountData().removeData(context); try { await Authenticate( @@ -36,23 +31,17 @@ class _LoginState extends State { user: data.name, password: data.password, ) - ).run().then((value) => { - log(value.sessionId) + ).run().then((value) async { + await AccountData().setData(context, data.name, data.password); + + setState(() { + displayDisclaimerText = false; + }); }); - } on WebuntisError catch(e) { - return e.toString(); - } on ApiError catch(e) { + } catch(e) { return e.toString(); } - setState(() { - displayDisclaimerText = false; - }); - - preferences.setBool("loggedIn", true); - preferences.setString("username", data.name); - preferences.setString("password", data.password); - return null; } @@ -69,7 +58,7 @@ class _LoginState extends State { userValidator: _checkInput, passwordValidator: _checkInput, - onSubmitAnimationCompleted: () => Provider.of(context, listen: false).login(), + onSubmitAnimationCompleted: () => Provider.of(context, listen: false).setState(AccountModelState.loggedIn), onLogin: _login, onSignup: null, diff --git a/lib/view/pages/files/files.dart b/lib/view/pages/files/files.dart index f42abb7..48e8691 100644 --- a/lib/view/pages/files/files.dart +++ b/lib/view/pages/files/files.dart @@ -4,8 +4,6 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:loader_overlay/loader_overlay.dart'; -import 'package:marianum_mobile/storage/base/settingsProvider.dart'; -import 'package:marianum_mobile/widget/loadingSpinner.dart'; import 'package:provider/provider.dart'; import '../../../api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart'; @@ -13,7 +11,9 @@ import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart' import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart'; import '../../../api/marianumcloud/webdav/webdavApi.dart'; import '../../../model/files/filesProps.dart'; -import '../../../widget/errorView.dart'; +import '../../../storage/base/settingsProvider.dart'; +import '../../../widget/loadingSpinner.dart'; +import '../../../widget/placeholderView.dart'; import '../../../widget/filePick.dart'; import 'fileUploadDialog.dart'; import 'fileElement.dart'; @@ -224,7 +224,7 @@ class _FilesState extends State { }, child: const Icon(Icons.add), ), - body: data == null ? const LoadingSpinner() : data!.files.isEmpty ? const ErrorView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : LoaderOverlay( + body: data == null ? const LoadingSpinner() : data!.files.isEmpty ? const PlaceholderView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : LoaderOverlay( child: RefreshIndicator( onRefresh: () { _query(); diff --git a/lib/view/pages/more/message/message.dart b/lib/view/pages/more/message/message.dart index 162f3fa..a1c2661 100644 --- a/lib/view/pages/more/message/message.dart +++ b/lib/view/pages/more/message/message.dart @@ -1,10 +1,9 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:marianum_mobile/widget/loadingSpinner.dart'; import 'package:provider/provider.dart'; import '../../../../api/mhsl/message/getMessages/getMessagesResponse.dart'; import '../../../../model/message/messageProps.dart'; +import '../../../../widget/loadingSpinner.dart'; import 'messageView.dart'; diff --git a/lib/view/pages/talk/chatBubble.dart b/lib/view/pages/talk/chatBubble.dart index c630980..918506e 100644 --- a/lib/view/pages/talk/chatBubble.dart +++ b/lib/view/pages/talk/chatBubble.dart @@ -4,12 +4,12 @@ import 'package:flowder/flowder.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:jiffy/jiffy.dart'; -import 'package:marianum_mobile/api/marianumcloud/talk/deleteMessage/deleteMessage.dart'; -import 'package:marianum_mobile/model/chatList/chatProps.dart'; import 'package:provider/provider.dart'; import '../../../api/marianumcloud/talk/chat/getChatResponse.dart'; +import '../../../api/marianumcloud/talk/deleteMessage/deleteMessage.dart'; import '../../../api/marianumcloud/talk/room/getRoomResponse.dart'; +import '../../../model/chatList/chatProps.dart'; import '../../../theming/appTheme.dart'; import '../../../widget/debug/debugTile.dart'; import '../files/fileElement.dart'; diff --git a/lib/view/pages/talk/chatList.dart b/lib/view/pages/talk/chatList.dart index 2b36c5b..86fd903 100644 --- a/lib/view/pages/talk/chatList.dart +++ b/lib/view/pages/talk/chatList.dart @@ -1,14 +1,14 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:marianum_mobile/api/marianumcloud/talk/createRoom/createRoomParams.dart'; -import 'package:marianum_mobile/widget/confirmDialog.dart'; -import 'package:marianum_mobile/widget/loadingSpinner.dart'; import 'package:provider/provider.dart'; import '../../../api/marianumcloud/talk/createRoom/createRoom.dart'; +import '../../../api/marianumcloud/talk/createRoom/createRoomParams.dart'; import '../../../model/chatList/chatListProps.dart'; import '../../../storage/base/settingsProvider.dart'; +import '../../../widget/confirmDialog.dart'; +import '../../../widget/loadingSpinner.dart'; import 'chatTile.dart'; import 'joinChat.dart'; import 'searchChat.dart'; diff --git a/lib/view/pages/talk/chatView.dart b/lib/view/pages/talk/chatView.dart index 9dfe68d..3fd4119 100644 --- a/lib/view/pages/talk/chatView.dart +++ b/lib/view/pages/talk/chatView.dart @@ -2,13 +2,13 @@ import 'package:flutter/material.dart'; import 'package:jiffy/jiffy.dart'; import 'package:loader_overlay/loader_overlay.dart'; -import 'package:marianum_mobile/widget/loadingSpinner.dart'; import 'package:provider/provider.dart'; import '../../../api/marianumcloud/talk/chat/getChatResponse.dart'; import '../../../api/marianumcloud/talk/room/getRoomResponse.dart'; import '../../../theming/appTheme.dart'; import '../../../model/chatList/chatProps.dart'; +import '../../../widget/loadingSpinner.dart'; import 'chatBubble.dart'; import 'chatTextfield.dart'; diff --git a/lib/view/pages/talk/joinChat.dart b/lib/view/pages/talk/joinChat.dart index f973b44..d8ed734 100644 --- a/lib/view/pages/talk/joinChat.dart +++ b/lib/view/pages/talk/joinChat.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import '../../../api/marianumcloud/autocomplete/autocompleteApi.dart'; import '../../../api/marianumcloud/autocomplete/autocompleteResponse.dart'; -import '../../../widget/errorView.dart'; +import '../../../widget/placeholderView.dart'; class JoinChat extends SearchDelegate { CancelableOperation? future; @@ -47,7 +47,7 @@ class JoinChat extends SearchDelegate { if(future != null) future!.cancel(); if(query.isEmpty) { - return const ErrorView( + return const PlaceholderView( text: "Suche nach benutzern", icon: Icons.person_search_outlined, ); @@ -81,7 +81,7 @@ class JoinChat extends SearchDelegate { ); } else if(snapshot.hasError) { log(snapshot.error.toString()); - return ErrorView(text: snapshot.error.toString()); + return PlaceholderView(icon: Icons.search_off, text: snapshot.error.toString()); } return const Center(child: CircularProgressIndicator()); diff --git a/lib/view/pages/timetable/timetable.dart b/lib/view/pages/timetable/timetable.dart index 0b6a38c..9fa7e08 100644 --- a/lib/view/pages/timetable/timetable.dart +++ b/lib/view/pages/timetable/timetable.dart @@ -2,7 +2,6 @@ import 'dart:developer'; import 'package:flutter/material.dart'; -import 'package:marianum_mobile/widget/loadingSpinner.dart'; import 'package:provider/provider.dart'; import 'package:syncfusion_flutter_calendar/calendar.dart'; @@ -11,7 +10,8 @@ import '../../../api/webuntis/queries/getRooms/getRoomsResponse.dart'; import '../../../api/webuntis/queries/getSubjects/getSubjectsResponse.dart'; import '../../../model/timetable/timetableProps.dart'; import '../../../storage/base/settingsProvider.dart'; -import '../../../widget/errorView.dart'; +import '../../../widget/loadingSpinner.dart'; +import '../../../widget/placeholderView.dart'; import 'appointmenetComponent.dart'; import 'appointmentDetails.dart'; import 'timeRegionComponent.dart'; @@ -68,7 +68,7 @@ class _TimetableState extends State { GetHolidaysResponse holidays = value.getHolidaysResponse; if(value.hasError) { - return ErrorView( + return PlaceholderView( icon: Icons.calendar_month, text: "Webuntis error: ${value.error.toString()}", ); diff --git a/lib/view/settings/settings.dart b/lib/view/settings/settings.dart index 6325f37..e13b3de 100644 --- a/lib/view/settings/settings.dart +++ b/lib/view/settings/settings.dart @@ -5,7 +5,7 @@ import 'package:package_info/package_info.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '../../model/accountModel.dart'; +import '../../model/accountData.dart'; import '../../storage/base/settingsProvider.dart'; import '../../theming/appTheme.dart'; import '../../widget/confirmDialog.dart'; @@ -52,9 +52,9 @@ class _SettingsState extends State { onConfirm: () { SharedPreferences.getInstance().then((value) => { value.clear(), - }).then((value) => { - Provider.of(context, listen: false).logout(), - Navigator.popUntil(context, (route) => !Navigator.canPop(context)), + }).then((value) { + AccountData().removeData(context); + Navigator.popUntil(context, (route) => !Navigator.canPop(context)); }); }, ), diff --git a/lib/widget/debug/cacheView.dart b/lib/widget/debug/cacheView.dart index b4fd454..c288ae3 100644 --- a/lib/widget/debug/cacheView.dart +++ b/lib/widget/debug/cacheView.dart @@ -7,7 +7,7 @@ import 'package:flutter/services.dart'; import 'package:jiffy/jiffy.dart'; import 'package:localstore/localstore.dart'; -import '../../../widget/errorView.dart'; +import '../../../widget/placeholderView.dart'; import 'jsonViewer.dart'; class CacheView extends StatefulWidget { @@ -93,7 +93,7 @@ class _CacheViewState extends State { ); } else { return const Center( - child: ErrorView(icon: Icons.hourglass_empty, text: "Keine Daten"), + child: PlaceholderView(icon: Icons.hourglass_empty, text: "Keine Daten"), ); } }, diff --git a/lib/widget/errorView.dart b/lib/widget/errorView.dart deleted file mode 100644 index 4a04f3a..0000000 --- a/lib/widget/errorView.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:flutter/material.dart'; - -class ErrorView extends StatelessWidget { - final IconData icon; - final String text; - const ErrorView({Key? key, this.icon = Icons.report_gmailerrorred, this.text = "Es ist ein Fehler aufgetreten!"}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Center( - child: Container( - margin: const EdgeInsets.only(top: 100, left: 20, right: 20), - child: Column( - children: [ - Container( - margin: const EdgeInsets.all(30), - child: Icon(icon, color: Colors.grey, size: 60), - ), - Text(text, - style: const TextStyle( - fontSize: 20, - color: Colors.grey, - ), - textAlign: TextAlign.center, - ), - ], - ), - ), - ); - } -} diff --git a/lib/widget/placeholderView.dart b/lib/widget/placeholderView.dart new file mode 100644 index 0000000..f2f198e --- /dev/null +++ b/lib/widget/placeholderView.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; + +class PlaceholderView extends StatelessWidget { + final IconData icon; + final String text; + const PlaceholderView({Key? key, required this.icon, required this.text}) : super(key: key); + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: const TextStyle(), + child: Center( + child: Container( + margin: const EdgeInsets.only(top: 100, left: 20, right: 20), + child: Column( + children: [ + Container( + margin: const EdgeInsets.all(30), + child: Icon(icon, color: Colors.grey, size: 60), + ), + Text(text, + style: const TextStyle( + fontSize: 20, + color: Colors.grey, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + ), + ); + } +}