12 changed files with 455 additions and 259 deletions
@ -1,15 +1,17 @@ |
|||||||
# shared_preferences_aurora |
# 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 |
```yaml |
||||||
[plug-in package](https://flutter.dev/developing-packages/), |
dependencies: |
||||||
a specialized package that includes platform-specific implementation code for |
shared_preferences: ^2.1.1 |
||||||
Android and/or iOS. |
shared_preferences_aurora: ^0.0.0 # @todo Not published |
||||||
|
``` |
||||||
|
|
||||||
For help getting started with Flutter development, view the |
### Preview example |
||||||
[online documentation](https://flutter.dev/docs), which offers tutorials, |
|
||||||
samples, guidance on mobile development, and a full API reference. |
|
||||||
|
|
||||||
|
 |
After Width: | Height: | Size: 91 KiB |
@ -1,45 +1,64 @@ |
|||||||
import 'shared_preferences_aurora_platform_interface.dart'; |
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 { |
class SharedPreferencesAurora extends SharedPreferencesStorePlatform { |
||||||
static void registerWith() {} |
SharedPreferencesAurora({ |
||||||
|
@visibleForTesting SharedPreferencesAuroraPlatform? api, |
||||||
|
}) : _api = api ?? SharedPreferencesAuroraPlatform.instance; |
||||||
|
|
||||||
Future<int> getInt(String key, int value) { |
late final SharedPreferencesAuroraPlatform _api; |
||||||
return SharedPreferencesAuroraPlatform.instance.getInt(key, value); |
|
||||||
} |
|
||||||
|
|
||||||
Future<bool> setInt(String key, int value) { |
|
||||||
return SharedPreferencesAuroraPlatform.instance.setInt(key, value); |
|
||||||
} |
|
||||||
|
|
||||||
Future<bool> getBool(String key, bool value) { |
/// Registers this class as the default instance of [SharedPreferencesStorePlatform]. |
||||||
return SharedPreferencesAuroraPlatform.instance.getBool(key, value); |
static void registerWith() { |
||||||
|
SharedPreferencesStorePlatform.instance = SharedPreferencesAurora(); |
||||||
} |
} |
||||||
|
|
||||||
Future<bool> setBool(String key, bool value) { |
static const String _defaultPrefix = 'flutter.'; |
||||||
return SharedPreferencesAuroraPlatform.instance.setBool(key, value); |
|
||||||
} |
|
||||||
|
|
||||||
Future<double> getDouble(String key, double value) { |
@override |
||||||
return SharedPreferencesAuroraPlatform.instance.getDouble(key, value); |
Future<bool> remove(String key) async { |
||||||
|
return _api.remove(key); |
||||||
} |
} |
||||||
|
|
||||||
Future<bool> setDouble(String key, double value) { |
@override |
||||||
return SharedPreferencesAuroraPlatform.instance.setDouble(key, value); |
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) { |
@override |
||||||
return SharedPreferencesAuroraPlatform.instance.getString(key, value); |
Future<bool> clear() { |
||||||
|
return clearWithPrefix(_defaultPrefix); |
||||||
} |
} |
||||||
|
|
||||||
Future<bool> setString(String key, String value) { |
@override |
||||||
return SharedPreferencesAuroraPlatform.instance.setString(key, value); |
Future<bool> clearWithPrefix(String prefix) async { |
||||||
|
return _api.clearWithPrefix(prefix); |
||||||
} |
} |
||||||
|
|
||||||
Future<List<String>> getStringList(String key, List<String> value) { |
@override |
||||||
return SharedPreferencesAuroraPlatform.instance.getStringList(key, value); |
Future<Map<String, Object>> getAll() { |
||||||
|
return getAllWithPrefix(_defaultPrefix); |
||||||
} |
} |
||||||
|
|
||||||
Future<bool> setStringList(String key, List<String> value) { |
@override |
||||||
return SharedPreferencesAuroraPlatform.instance.setStringList(key, value); |
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