Skip to content

Commit

Permalink
fix: bug with secure storage juliansteenbakker/flutter_secure_storage…
Browse files Browse the repository at this point in the history
  • Loading branch information
sergdeus committed Sep 13, 2022
1 parent 9132ad0 commit 70ac547
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
9 changes: 3 additions & 6 deletions lib/core/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ class _AppState extends State<App> with WidgetsBindingObserver, StringMixin, Cou
}

/// Configure [ApiClient] with cache
String? token;
try {
// fixing this https://github.com/mogol/flutter_secure_storage/issues/43#issuecomment-471642126
token = await _secureStorage.read(SecureStorageKey.token);
} catch (e) {
_secureStorage.deleteAll();
Expand All @@ -248,12 +250,7 @@ class _AppState extends State<App> with WidgetsBindingObserver, StringMixin, Cou
_api.accessToken = token;

/// Set pin code state
String? pin;
try {
pin = await _secureStorage.read(SecureStorageKey.pin);
} catch (e) {
_secureStorage.deleteAll();
}
final String? pin = await _secureStorage.read(SecureStorageKey.pin);

appState.hasPinCode = token != null && pin != null;
appState.pinCode = pin;
Expand Down
7 changes: 1 addition & 6 deletions lib/features/main/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,7 @@ class _MainScreenState extends State<MainScreen> {
} else {
await SecureStorage.ensureInitialized();
final SecureStorage _secureStorage = SecureStorage();
String? l;
try {
l = await _secureStorage.read(SecureStorageKey.locale);
} catch (e) {
_secureStorage.deleteAll();
}
final String? l = await _secureStorage.read(SecureStorageKey.locale);
final langCode = l ?? Platform.localeName.substring(0, 2);
await FlutterForegroundTask.startService(
notificationTitle:
Expand Down
9 changes: 1 addition & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,7 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
try {
await SecureStorage.ensureInitialized();
final SecureStorage _secureStorage = SecureStorage();

String? l;
try {
l = await _secureStorage.read(SecureStorageKey.locale);
} catch (e) {
_secureStorage.deleteAll();
}

final l = await _secureStorage.read(SecureStorageKey.locale);
final String langCode = l ?? Platform.localeName.substring(0, 2);
final PushModel push = PushModel.fromJson(message.data);
final Map<String, String> payload = push.toJson().map((key, value) => MapEntry(key, value?.toString() ?? ''));
Expand Down

0 comments on commit 70ac547

Please sign in to comment.