Merge pull request #2 from traccar/codex/validate-and-show-error-for-server-url
Fix preference migration
This commit is contained in:
commit
a543681b1a
3 changed files with 16 additions and 9 deletions
|
|
@ -4,9 +4,10 @@ import 'dart:math';
|
|||
|
||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:shared_preferences_android/shared_preferences_android.dart';
|
||||
|
||||
class Preferences {
|
||||
static late SharedPreferences instance;
|
||||
static late SharedPreferencesWithCache instance;
|
||||
static const String id = 'id';
|
||||
static const String url = 'url';
|
||||
static const String accuracy = 'accuracy';
|
||||
|
|
@ -15,7 +16,18 @@ class Preferences {
|
|||
static const String buffer = 'buffer';
|
||||
|
||||
static Future<void> init() async {
|
||||
instance = await SharedPreferences.getInstance();
|
||||
instance = await SharedPreferencesWithCache.create(
|
||||
sharedPreferencesOptions: Platform.isAndroid
|
||||
? SharedPreferencesAsyncAndroidOptions(backend: SharedPreferencesAndroidBackendLibrary.SharedPreferences)
|
||||
: SharedPreferencesOptions(),
|
||||
cacheOptions: SharedPreferencesWithCacheOptions(
|
||||
allowList: {
|
||||
'id', 'url', 'accuracy', 'interval', 'distance', 'buffer',
|
||||
'device_id_preference', 'server_url_preference', 'accuracy_preference',
|
||||
'frequency_preference', 'distance_preference', 'buffer_preference',
|
||||
},
|
||||
),
|
||||
);
|
||||
if (Platform.isIOS) {
|
||||
await _migrate();
|
||||
}
|
||||
|
|
@ -113,12 +125,6 @@ class Preferences {
|
|||
instance.setInt(distance, oldDistance);
|
||||
instance.remove('distance_preference');
|
||||
}
|
||||
final oldAngleString = instance.getString('angle_preference');
|
||||
final oldAngle = oldAngleString != null ? int.tryParse(oldAngleString) : null;
|
||||
if (oldAngle != null) {
|
||||
instance.setInt('angle', oldAngle);
|
||||
instance.remove('angle_preference');
|
||||
}
|
||||
final oldBuffer = instance.getBool('buffer_preference');
|
||||
if (oldBuffer != null) {
|
||||
instance.setBool(buffer, oldBuffer);
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ packages:
|
|||
source: hosted
|
||||
version: "2.5.3"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "20cbd561f743a342c76c151d6ddb93a9ce6005751e7aa458baad3858bfbfb6ac"
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ dependencies:
|
|||
firebase_crashlytics: ^4.3.5
|
||||
quick_actions: ^1.1.0
|
||||
rate_my_app: ^2.3.1
|
||||
shared_preferences_android: ^2.4.10
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue