dartpub.dev DartNative · beta
plugins / dartnative_shared_preferences
ds

dartnative_shared_preferences

v1.0.0 dartpub Free

Native key-value preferences

The native key–value preferences for DartNative — simple typed storage behind the familiar `shared_preferences` API, backed by `NSUserDefaults` on iOS and `SharedPreferences` on Android. Works from any isolate, no platform channel.

by DartNative/dartnative_shared_preferences · DartNative ≥ 3.0 · updated 3 weeks ago
Install
Free
pubspec.yaml
dependencies:
  dartnative_shared_preferences: ^1.0.0
Weekly installs
40
Active apps
13
Rating
0.0 · 0
Open issues
0

dartnative_shared_preferences

Simple key–value preferences for DartNative — NSUserDefaults on iOS, SharedPreferences on Android — with the familiar shared_preferences API. iOS and Android.

Why you'll like it

  • Familiar APIgetInstance(), then getString / setBool / …, like shared_preferences.
  • All the common typesString, int, double, bool, List<String>.
  • Works from any isolate — no platform channel, so reads and writes work outside the main isolate.
  • Zero setup — backed by the platform's native defaults via the DartNative framework.

Highlights

  • SharedPreferences.getInstance() → the store.
  • getString / getInt / getDouble / getBool / getStringList (+ containsKey).
  • setString / setInt / setDouble / setBool / setStringList, plus remove / clear / reload.

getKeys() (enumerate all keys) isn't available yet.

Install

dependencies:
  dartnative_shared_preferences: ^1.0.0   # from dartpub.dev
dn pub get
void main() {
  DartNativePluginRegistrant.registerAll();
  runApp(const MyApp());
}

Quick look

import 'package:dartnative_shared_preferences/dartnative_shared_preferences.dart';

final prefs = await SharedPreferences.getInstance();

await prefs.setString('name', 'Ada');
await prefs.setBool('onboarded', true);

final name = prefs.getString('name');     // 'Ada'
final done = prefs.getBool('onboarded');  // true

Platform setup

iOS

No native setup required.

Android

No native setup required.

Example

The example/ app stores and reads a few settings — borrow from it freely.

Credits & license

API mirrors Flutter's shared_preferences (BSD-3-Clause); the plugin ships its own native bridge — NSUserDefaults on iOS, SharedPreferences on Android — over FFI, built on the DartNative framework's runtime (FFI loader, and the Android application context).

Commercial plugin distributed via dartpub.dev — file issues on the plugin's page.