shared_preferences 0.5.7+3 copy "shared_preferences: ^0.5.7+3" to clipboard
shared_preferences: ^0.5.7+3 copied to clipboard

outdated

Flutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.

Shared preferences plugin #

pub package

Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data. Data is persisted to disk asynchronously. Neither platform can guarantee that writes will be persisted to disk after returning and this plugin must not be used for storing critical data.

Please set your constraint to shared_preferences: '>=0.5.y+x <2.0.0'

Backward compatible 1.0.0 version is coming #

The plugin has reached a stable API, we guarantee that version 1.0.0 will be backward compatible with 0.5.y+z. Please use shared_preferences: '>=0.5.y+x <2.0.0' as your dependency constraint to allow a smoother ecosystem migration. For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0

Usage #

To use this plugin, add shared_preferences as a dependency in your pubspec.yaml file.

Example #

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
      child: RaisedButton(
        onPressed: _incrementCounter,
        child: Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);
}

Testing #

You can populate SharedPreferences with initial values in your tests by running this code:

SharedPreferences.setMockInitialValues (Map<String, dynamic> values);
8920
likes
0
pub points
100%
popularity

Publisher

verified publisherflutter.dev

Flutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, meta, shared_preferences_macos, shared_preferences_platform_interface, shared_preferences_web

More

Packages that depend on shared_preferences