flutterx_preferences 2.0.0 copy "flutterx_preferences: ^2.0.0" to clipboard
flutterx_preferences: ^2.0.0 copied to clipboard

Persistent and session key-value storage exposed as a synchronous Map<String, String>, with typed accessors for bool, int, double, JSON and lists.

2.0.0 #

Major release: rewritten on Dart 3.11 / Flutter 3.41 with package:web, atomic file writes and a single instance per storage. The synchronous Storage = Map<String, String> contract and the on-disk files are unchanged: existing data on mobile and desktop is read without migration.

  • Breaking: requires Dart ^3.11.0 and Flutter >=3.41.0.
  • Breaking: localStorage and sessionStorage are getters on every platform (they were reassignable variables on IO).
  • Breaking: Preferences.set<T>, get<T> and opt<T> removed: use setString/setJson/setList and the typed accessors.
  • Breaking: setList<T>(key, Iterable<T>?, {required encode}): encode is required and items are no longer JSON-encoded twice; the stored format equals the one produced before with an explicit encode.
  • Breaking: optBool/getBool accept only 'true' and 'false'; any other value reads as null/fallback (it was false).
  • Breaking: optJson/getJson/optList/getList return null/fallback when the stored text is malformed (they threw); exceptions thrown by fromJson/decode always propagate.
  • Breaking: storage names must match ^[A-Za-z0-9_-]+$, otherwise ArgumentError.
  • Breaking (web): named storages are stored under the key flutterx_preferences:<name> (was <name>) and Preferences.local() without a name uses window.localStorage directly (was a blob under _local_). Data saved on the web with loadLocalStorage/Preferences.local is not read anymore; localStorage hides the reserved keys.
  • New setJson(key, Map<String, Object?>?).
  • localStorage and Preferences.local() are the same instance, as are loadLocalStorage(name) and Preferences.local(name): writes are no longer lost between copies.
  • IO writes are atomic (temporary file + rename); a file that cannot be read or decoded loads as an empty storage and is reported with FlutterError.reportError instead of crashing the app; non-string values are read as their JSON text.
  • Removed the platform dependency and dart:html.
  • Integration skills for Claude Code in .claude-plugin/ and skills/.

Migration from 1.x #

  1. Raise the app to Dart 3.11 / Flutter 3.41 and depend on flutterx_preferences: ^2.0.0.
  2. Replace assignments to localStorage/sessionStorage with writes into the map (localStorage.addAll(...)).
  3. Replace prefs.set<T>(key, value) with setString, setInt, setJson(key, value.toJson()) or setList(key, values, encode: ...); replace get<T>/opt<T> with the typed accessor plus your own conversion.
  4. Add encode: to every setList call (encode: (s) => s for strings; for other types the encoder you pass to getList's decode counterpart).
  5. If the app relied on optBool returning false for unknown values, use getBool(key, fallback: false).
  6. Use only letters, digits, _ and - in storage names.
  7. Web only: to keep data written by 1.x with Preferences.local('x'), copy window.localStorage['x'] into loadLocalStorage('x') once at startup.

1.2.5 #

  • Remove LiveData dependency

1.2.4 #

  • Refactoring, add local storage map support

1.2.3 #

  • Fix web error

1.2.2 #

  • Refactoring

1.2.1 #

  • Add json methods

1.2.0 #

  • Improvements

1.1.1-dev #

  • Improvements

1.1.0 #

  • Initial stable release

1.0.5-dev #

  • Platform management improvements.

1.0.4-dev #

  • Add web support.

1.0.3-dev #

  • Fix dispatcher for LivePreferences.

1.0.2-dev #

  • Make everything synchronous.

1.0.1-dev #

  • Fix.

1.0.0-dev #

  • Initial release.
1
likes
160
points
120
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Persistent and session key-value storage exposed as a synchronous Map<String, String>, with typed accessors for bool, int, double, JSON and lists.

Repository (GitLab)
View/report issues

License

BSD-3-Clause (license)

Dependencies

flutter, path_provider, web

More

Packages that depend on flutterx_preferences