Repository navigation
[shared_preferences] Update shared_preferences_android and shared_preferences_foundation to Pigeon 29.0.13 and jni 1.1.1 - #13497
Conversation
…o Pigeon 29.0.13 and jni 1.1.1
There was a problem hiding this comment.
Code Review
This pull request updates the shared_preferences_android and shared_preferences_foundation packages to use Pigeon 29.0.13 and jni 1.1.1. These updates allow for the removal of manual web conditional FFI export workarounds, stub files, and R8 consumer rules. The platform-specific options classes have been moved directly into the main implementation files. Feedback suggests importing package:meta/meta.dart and annotating the Android options classes with @immutable along with adding a fromSharedPreferencesOptions helper method for consistency across platforms.
| import 'package:shared_preferences_platform_interface/types.dart'; | ||
|
|
||
| import 'messages_async.g.dart'; | ||
| import 'shared_preferences_async_android_options.dart'; | ||
| import 'strings.dart'; |
There was a problem hiding this comment.
Import package:meta/meta.dart to support the @immutable annotation on the options classes.
| import 'package:shared_preferences_platform_interface/types.dart'; | |
| import 'messages_async.g.dart'; | |
| import 'shared_preferences_async_android_options.dart'; | |
| import 'strings.dart'; | |
| import 'package:meta/meta.dart'; | |
| import 'package:shared_preferences_platform_interface/types.dart'; | |
| import 'messages_async.g.dart'; | |
| import 'strings.dart'; |
| /// Options for the Android specific SharedPreferences plugin. | ||
| class SharedPreferencesAsyncAndroidOptions extends SharedPreferencesOptions { | ||
| /// Constructor for SharedPreferencesAsyncAndroidOptions. | ||
| const SharedPreferencesAsyncAndroidOptions({ | ||
| this.backend = SharedPreferencesAndroidBackendLibrary.DataStore, | ||
| this.originalSharedPreferencesOptions, | ||
| }); | ||
|
|
||
| /// Which backend should be used for this method call. | ||
| final SharedPreferencesAndroidBackendLibrary backend; | ||
|
|
||
| /// These options define how the `SharedPreferences` backend should behave. | ||
| /// | ||
| /// Any options in this field will be ignored unless the backend that is selected | ||
| /// is `SharedPreferences`. | ||
| final AndroidSharedPreferencesStoreOptions? originalSharedPreferencesOptions; | ||
| } | ||
|
|
||
| /// Options necessary for defining the use of the original `SharedPreferences` | ||
| /// library. | ||
| /// | ||
| /// These options are only ever used with the original `SharedPreferences` and | ||
| /// have no purpose when using the default DataStore Preferences. | ||
| class AndroidSharedPreferencesStoreOptions { | ||
| /// Constructor for AndroidSharedPreferencesStoreOptions. | ||
| const AndroidSharedPreferencesStoreOptions({this.fileName}); | ||
|
|
||
| /// The name of the file in which the preferences are stored. | ||
| final String? fileName; | ||
| } |
There was a problem hiding this comment.
For consistency with SharedPreferencesAsyncFoundationOptions and to follow best practices for configuration classes, SharedPreferencesAsyncAndroidOptions and AndroidSharedPreferencesStoreOptions should be annotated with @immutable. Additionally, adding a fromSharedPreferencesOptions static helper method to SharedPreferencesAsyncAndroidOptions will make the API consistent across both platform implementations.
/// Options for the Android specific SharedPreferences plugin.
@immutable
class SharedPreferencesAsyncAndroidOptions extends SharedPreferencesOptions {
/// Constructor for SharedPreferencesAsyncAndroidOptions.
const SharedPreferencesAsyncAndroidOptions({
this.backend = SharedPreferencesAndroidBackendLibrary.DataStore,
this.originalSharedPreferencesOptions,
});
/// Which backend should be used for this method call.
final SharedPreferencesAndroidBackendLibrary backend;
/// These options define how the `SharedPreferences` backend should behave.
///
/// Any options in this field will be ignored unless the backend that is selected
/// is `SharedPreferences`.
final AndroidSharedPreferencesStoreOptions? originalSharedPreferencesOptions;
/// Returns a new instance of [SharedPreferencesAsyncAndroidOptions] from an existing
/// [SharedPreferencesOptions].
static SharedPreferencesAsyncAndroidOptions fromSharedPreferencesOptions(
SharedPreferencesOptions options,
) {
if (options is SharedPreferencesAsyncAndroidOptions) {
return options;
}
return const SharedPreferencesAsyncAndroidOptions();
}
}
/// Options necessary for defining the use of the original `SharedPreferences`
/// library.
///
/// These options are only ever used with the original `SharedPreferences` and
/// have no purpose when using the default DataStore Preferences.
@immutable
class AndroidSharedPreferencesStoreOptions {
/// Constructor for AndroidSharedPreferencesStoreOptions.
const AndroidSharedPreferencesStoreOptions({this.fileName});
/// The name of the file in which the preferences are stored.
final String? fileName;
}
Updates
shared_preferences_androidandshared_preferences_foundationtopigeon: ^29.0.13(#13393) andjni: ^1.1.1, and cleans up the manual workarounds that are now handled upstream:29.0.13conditional native interop imports: Regenerates Pigeon files sodart:ffi,package:jni, andpackage:objective_cbindings live in*.native_interop.g.dartbehindif (dart.library.ffi), allowing*.g.dartto be imported directly on Web. Removes the manual*_real.dart/*_stub.dartconditional export files and separate*_options.dartfiles added as workarounds in [shared_preferences_android] Fix web compilation of apps that import the package #13380 and [shared_preferences_foundation] Fix web compilation of apps that import the package #13447.jni: ^1.1.1consumer keep rules: Bumpsjnito^1.1.1inshared_preferences_androidand removes the manualandroid/consumer-rules.proworkaround added in [shared_preferences] Keep Kotlin classes used through JNI in Android release builds #13311, aspackage:jninow ships those ProGuard/R8 keep rules directly ([jnigen] Suspend functions fail in minified release builds: keep the Kotlin classes jni looks up by name dart-lang/native#3732).shared_preferencesmigration integration test: AddskIsWebguards beforePlatform.is*checks inshared_preferences/example/integration_test/shared_preferences_migration_util_test.dart.Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2