Skip to content

[shared_preferences] Update shared_preferences_android and shared_preferences_foundation to Pigeon 29.0.13 and jni 1.1.1 - #13497

Closed
tarrinneal wants to merge 1 commit into
flutter:mainfrom
tarrinneal:shared-preferences-pigeon-29.0.13
Closed

tarrinneal wants to merge 1 commit into
flutter:mainfrom
tarrinneal:shared-preferences-pigeon-29.0.13

Conversation

@tarrinneal

Copy link
Copy Markdown
Contributor

Updates shared_preferences_android and shared_preferences_foundation to pigeon: ^29.0.13 (#13393) and jni: ^1.1.1, and cleans up the manual workarounds that are now handled upstream:

Pre-Review Checklist

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-assist bot 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

  1. 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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 10 to 13
import 'package:shared_preferences_platform_interface/types.dart';

import 'messages_async.g.dart';
import 'shared_preferences_async_android_options.dart';
import 'strings.dart';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Import package:meta/meta.dart to support the @immutable annotation on the options classes.

Suggested change
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';

Comment on lines +235 to +264
/// 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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
}

@tarrinneal tarrinneal closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant