TF-474 Fix data in cache not show correctly after logout

This commit is contained in:
dab246
2022-04-12 11:41:14 +07:00
committed by Dat H. Pham
parent 04ef997eb4
commit b4fd1ce5e5
7 changed files with 50 additions and 10 deletions
+14 -5
View File
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:tmail_ui_user/features/caching/email_cache_client.dart';
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
@@ -16,10 +17,18 @@ class CachingManager {
);
Future<void> clearAll() async {
await Future.wait([
_stateCacheClient.deleteBox(),
_mailboxCacheClient.deleteBox(),
_emailCacheClient.deleteBox(),
]);
if (kIsWeb) {
await Future.wait([
_stateCacheClient.clearAllData(),
_mailboxCacheClient.clearAllData(),
_emailCacheClient.clearAllData(),
]);
} else {
await Future.wait([
_stateCacheClient.deleteBox(),
_mailboxCacheClient.deleteBox(),
_emailCacheClient.deleteBox(),
]);
}
}
}
@@ -30,4 +30,6 @@ abstract class HiveCacheClient<T> {
Future<void> deleteBox() {
return Hive.deleteBoxFromDisk(tableName);
}
Future<void> clearAllData();
}
@@ -135,4 +135,14 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
throw error;
});
}
@override
Future<void> clearAllData() {
return Future.sync(() async {
final boxEmail = await openBox();
boxEmail.clear();
}).catchError((error) {
throw error;
});
}
}
@@ -118,4 +118,14 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
throw error;
});
}
@override
Future<void> clearAllData() {
return Future.sync(() async {
final boxMailbox = await openBox();
boxMailbox.clear();
}).catchError((error) {
throw error;
});
}
}
@@ -118,4 +118,14 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
throw error;
});
}
@override
Future<void> clearAllData() {
return Future.sync(() async {
final boxState = await openBox();
boxState.clear();
}).catchError((error) {
throw error;
});
}
}
@@ -430,8 +430,8 @@ class MailboxDashBoardController extends ReloadableController {
void logoutAction() {
_deleteCredential();
if (!kIsWeb) _clearAllCache();
pushAndPopAll(AppRoutes.LOGIN);
_clearAllCache();
goToLogin();
}
@override
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart';
@@ -41,8 +40,8 @@ class SessionController extends GetxController {
void _goToLogin() {
_deleteCredential();
if (!kIsWeb) _clearAllCache();
pushAndPop(AppRoutes.LOGIN);
_clearAllCache();
pushAndPopAll(AppRoutes.LOGIN);
}
void _goToMailboxDashBoard(GetSessionSuccess getSessionSuccess) {