-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from Hive to shared_preferences + flutter_secure_storage (#61)
* Change settings storage from Hive to shared prefs * Use secure storage instead of Hive to store token * Remove Hive from dependencies * Wrap prefs and secure storage instances with providers * Upgrade secure storage package (somehow used v4 before) * Fix settings test * Fix API service alive behavior & fix tests * Fix profile tests * Implement mocked fetch profile * Add missing `equals` * Separate token provider & fix profile unit test * Fix typo * Move keepAlive call
- Loading branch information
1 parent
ca2fe00
commit 5e92cfb
Showing
34 changed files
with
402 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
part 'prefs.g.dart'; | ||
|
||
@riverpod | ||
Future<SharedPreferences> prefs(PrefsRef ref) => | ||
SharedPreferences.getInstance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'secure_storage.g.dart'; | ||
|
||
@riverpod | ||
Future<SecureStorage> secureStorage(SecureStorageRef ref) => | ||
SecureStorage.getInstance(keys: {'token'}); | ||
|
||
class SecureStorage { | ||
SecureStorage._(this._flutterSecureStorage, this._cache); | ||
|
||
late final FlutterSecureStorage _flutterSecureStorage; | ||
|
||
late final Map<String, String> _cache; | ||
|
||
static Future<SecureStorage> getInstance({required Set<String> keys}) async { | ||
const flutterSecureStorage = FlutterSecureStorage(); | ||
final cache = <String, String>{}; | ||
await keys | ||
.map((key) => flutterSecureStorage.read(key: key).then((value) { | ||
if (value != null) { | ||
cache[key] = value; | ||
} | ||
})) | ||
.wait; | ||
return SecureStorage._(flutterSecureStorage, cache); | ||
} | ||
|
||
String? get(String key) => _cache[key]; | ||
|
||
Future<void> set(String key, String value) { | ||
_cache[key] = value; | ||
return _flutterSecureStorage.write(key: key, value: value); | ||
} | ||
|
||
Future<void> remove(String key) { | ||
_cache.remove(key); | ||
return _flutterSecureStorage.delete(key: key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
|
||
list(APPEND FLUTTER_PLUGIN_LIST | ||
flutter_secure_storage_linux | ||
) | ||
|
||
list(APPEND FLUTTER_FFI_PLUGIN_LIST | ||
|
Oops, something went wrong.