Skip to content

Commit

Permalink
[234] Add flutter_secure_storage library
Browse files Browse the repository at this point in the history
  • Loading branch information
nmint8m committed Aug 22, 2023
1 parent b2851fd commit 72bf676
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:injectable/injectable.dart';

@module
abstract class StorageModule {
@singleton
FlutterSecureStorage get flutterSecureStorage => const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:injectable/injectable.dart';

const _keyAccessToken = 'KEY_ACCESS_TOKEN';

abstract class SecureStorage {
Future<String?> get accessToken;

Future<void> storeAccessToken(String accessToken);

Future<void> clearAllStorage();
}

@Singleton(as: SecureStorage)
class SecureStorageImpl extends SecureStorage {
final FlutterSecureStorage _storage;

SecureStorageImpl(this._storage);

@override
Future<String?> get accessToken => _storage.read(key: _keyAccessToken);

@override
Future<void> storeAccessToken(String accessToken) {
return _storage.write(key: _keyAccessToken, value: accessToken);
}

@override
Future<void> clearAllStorage() {
return _storage.deleteAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies:
json_annotation: ^4.8.1
package_info_plus: ^4.0.0{{#add_permission_handler}}{{{ _pubspec_dependencyyaml }}}{{/add_permission_handler}}
retrofit: ^4.0.1
flutter_secure_storage: ^8.0.0

dev_dependencies:
build_runner: ^2.4.4
Expand Down

0 comments on commit 72bf676

Please sign in to comment.