Skip to content

Commit

Permalink
Reset providers when logging out
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed Jul 30, 2023
1 parent e8afc2a commit 883c583
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions uni/lib/controller/logout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import 'package:uni/controller/local_storage/app_lectures_database.dart';
import 'package:uni/controller/local_storage/app_shared_preferences.dart';
import 'package:uni/controller/local_storage/app_user_database.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/providers/state_providers.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';

Future<void> logout(BuildContext context) async {
StateProviders.fromContext(context).markAsNotInitialized();

final prefs = await SharedPreferences.getInstance();
final faculties = await AppSharedPreferences.getUserFaculties();
await prefs.clear();
Expand Down
14 changes: 12 additions & 2 deletions uni/lib/model/providers/state_provider_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ abstract class StateProviderNotifier extends ChangeNotifier {
required this.cacheDuration,
RequestStatus initialStatus = RequestStatus.busy,
bool initialize = true,
}) : _status = initialStatus,
}) : _initialStatus = initialStatus,
_status = initialStatus,
_initializedFromStorage = !initialize,
_initializedFromRemote = !initialize;
static final Lock _lock = Lock();

final Lock _lock = Lock();
final RequestStatus _initialStatus;
RequestStatus _status;
bool _initializedFromStorage;
bool _initializedFromRemote;
Expand All @@ -31,6 +34,13 @@ abstract class StateProviderNotifier extends ChangeNotifier {

DateTime? get lastUpdateTime => _lastUpdateTime;

void markAsNotInitialized() {
_initializedFromStorage = false;
_initializedFromRemote = false;
_status = _initialStatus;
_lastUpdateTime = null;
}

Future<void> _loadFromStorage() async {
_lastUpdateTime = await AppSharedPreferences.getLastDataClassUpdateTime(
runtimeType.toString(),
Expand Down
15 changes: 15 additions & 0 deletions uni/lib/model/providers/state_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,19 @@ class StateProviders {
final FacultyLocationsProvider facultyLocationsProvider;
final HomePageProvider homePageProvider;
final ReferenceProvider referenceProvider;

void markAsNotInitialized() {
lectureProvider.markAsNotInitialized();
examProvider.markAsNotInitialized();
busStopProvider.markAsNotInitialized();
restaurantProvider.markAsNotInitialized();
courseUnitsInfoProvider.markAsNotInitialized();
profileProvider.markAsNotInitialized();
sessionProvider.markAsNotInitialized();
calendarProvider.markAsNotInitialized();
libraryOccupationProvider.markAsNotInitialized();
facultyLocationsProvider.markAsNotInitialized();
homePageProvider.markAsNotInitialized();
referenceProvider.markAsNotInitialized();
}
}

0 comments on commit 883c583

Please sign in to comment.