native_shared_preferences
이 패키지는 키에 접두사가 없는 shared_preferences 패키지의 사본입니다. 이전 네이티브 앱에서 데이터를 마이그레이션하는 데 사용됩니다.
yeniel/native_shared_preferences open-source repository details.
{"sdk":"flutter"}^1.9.1^2.2.2^2.3.1^2.3.2^2.0.5^2.2.1^2.3.2^7.0.0^1.0.6{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
===========
This plugin is a copy of the shared_preferences package but without the prefix in the keys. Is used to migrate the data from previous native app.
The issue is that flutter add a prefix to the keys when read and write. So we can not read our old keys.
Also for Android you can now specify name of your resource file in android/app/src/main/res/values/strings.xml:
<resources>
...
<string name="flutter_shared_pref_name">resource_name</string>
...
</resources>
ISSUE https://github.com/flutter/flutter/issues/52544
Only use this plugin when is needed get the shared preferences from previous native app version. For other situation use the official shared preferences package.
To manage the migration use this package https://pub.dev/packages/version_migration/
Add in pubspec:
native_shared_preferences: ^2.0.10
To use this plugin, add native_shared_preferences in your pubspec.yaml file
import 'package:flutter/material.dart';
import 'package:native_shared_preferences/native_shared_preferences.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: RaisedButton(
onPressed: _incrementCounter,
child: Text('Increment Counter'),
),
),
),
));
}
_incrementCounter() async {
NativeSharedPreferences prefs = await NativeSharedPreferences.getInstance();
int counter = (prefs.getInt('counter') ?? 0) + 1;
print('Pressed $counter times.');
await prefs.setInt('counter', counter);
}
You can populate NativeSharedPreferences with initial values in your tests by running this code:
NativeSharedPreferences.setMockInitialValues (Map<String, dynamic> values);