12 changed files with 455 additions and 259 deletions
@ -1,15 +1,17 @@
|
||||
# shared_preferences_aurora |
||||
|
||||
A new Flutter plugin project. |
||||
The Aurora implementation of [`shared_preferences`][https://pub.dev/packages/shared_preferences]. |
||||
|
||||
## Getting Started |
||||
## Usage |
||||
This package is not an _endorsed_ implementation of `shared_preferences`. |
||||
Therefore, you have to include `path_provider_aurora` alongside `shared_preferences` as dependencies in your `pubspec.yaml` file. |
||||
|
||||
This project is a starting point for a Flutter |
||||
[plug-in package](https://flutter.dev/developing-packages/), |
||||
a specialized package that includes platform-specific implementation code for |
||||
Android and/or iOS. |
||||
```yaml |
||||
dependencies: |
||||
shared_preferences: ^2.1.1 |
||||
shared_preferences_aurora: ^0.0.0 # @todo Not published |
||||
``` |
||||
|
||||
For help getting started with Flutter development, view the |
||||
[online documentation](https://flutter.dev/docs), which offers tutorials, |
||||
samples, guidance on mobile development, and a full API reference. |
||||
### Preview example |
||||
|
||||
 |
After Width: | Height: | Size: 91 KiB |
@ -1,45 +1,64 @@
|
||||
import 'shared_preferences_aurora_platform_interface.dart'; |
||||
import 'package:flutter/foundation.dart'; |
||||
import 'package:flutter/services.dart'; |
||||
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; |
||||
|
||||
class SharedPreferencesAurora { |
||||
static void registerWith() {} |
||||
class SharedPreferencesAurora extends SharedPreferencesStorePlatform { |
||||
SharedPreferencesAurora({ |
||||
@visibleForTesting SharedPreferencesAuroraPlatform? api, |
||||
}) : _api = api ?? SharedPreferencesAuroraPlatform.instance; |
||||
|
||||
Future<int> getInt(String key, int value) { |
||||
return SharedPreferencesAuroraPlatform.instance.getInt(key, value); |
||||
} |
||||
|
||||
Future<bool> setInt(String key, int value) { |
||||
return SharedPreferencesAuroraPlatform.instance.setInt(key, value); |
||||
} |
||||
late final SharedPreferencesAuroraPlatform _api; |
||||
|
||||
Future<bool> getBool(String key, bool value) { |
||||
return SharedPreferencesAuroraPlatform.instance.getBool(key, value); |
||||
/// Registers this class as the default instance of [SharedPreferencesStorePlatform]. |
||||
static void registerWith() { |
||||
SharedPreferencesStorePlatform.instance = SharedPreferencesAurora(); |
||||
} |
||||
|
||||
Future<bool> setBool(String key, bool value) { |
||||
return SharedPreferencesAuroraPlatform.instance.setBool(key, value); |
||||
} |
||||
static const String _defaultPrefix = 'flutter.'; |
||||
|
||||
Future<double> getDouble(String key, double value) { |
||||
return SharedPreferencesAuroraPlatform.instance.getDouble(key, value); |
||||
@override |
||||
Future<bool> remove(String key) async { |
||||
return _api.remove(key); |
||||
} |
||||
|
||||
Future<bool> setDouble(String key, double value) { |
||||
return SharedPreferencesAuroraPlatform.instance.setDouble(key, value); |
||||
@override |
||||
Future<bool> setValue(String valueType, String key, Object value) async { |
||||
switch (valueType) { |
||||
case 'String': |
||||
return _api.setString(key, value as String); |
||||
case 'Bool': |
||||
return _api.setBool(key, value as bool); |
||||
case 'Int': |
||||
return _api.setInt(key, value as int); |
||||
case 'Double': |
||||
return _api.setDouble(key, value as double); |
||||
case 'StringList': |
||||
return _api.setStringList(key, value as List<String>); |
||||
} |
||||
throw PlatformException( |
||||
code: 'InvalidOperation', |
||||
message: '"$valueType" is not a supported type.'); |
||||
} |
||||
|
||||
Future<String> getString(String key, String value) { |
||||
return SharedPreferencesAuroraPlatform.instance.getString(key, value); |
||||
@override |
||||
Future<bool> clear() { |
||||
return clearWithPrefix(_defaultPrefix); |
||||
} |
||||
|
||||
Future<bool> setString(String key, String value) { |
||||
return SharedPreferencesAuroraPlatform.instance.setString(key, value); |
||||
@override |
||||
Future<bool> clearWithPrefix(String prefix) async { |
||||
return _api.clearWithPrefix(prefix); |
||||
} |
||||
|
||||
Future<List<String>> getStringList(String key, List<String> value) { |
||||
return SharedPreferencesAuroraPlatform.instance.getStringList(key, value); |
||||
@override |
||||
Future<Map<String, Object>> getAll() { |
||||
return getAllWithPrefix(_defaultPrefix); |
||||
} |
||||
|
||||
Future<bool> setStringList(String key, List<String> value) { |
||||
return SharedPreferencesAuroraPlatform.instance.setStringList(key, value); |
||||
@override |
||||
Future<Map<String, Object>> getAllWithPrefix(String prefix) async { |
||||
final Map<Object?, Object?> data = await _api.getAllWithPrefix(prefix); |
||||
return data.cast<String, Object>(); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue