shared_preferences_hhz 2.0.13 copy "shared_preferences_hhz: ^2.0.13" to clipboard
shared_preferences_hhz: ^2.0.13 copied to clipboard

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

Shared preferences plugin #

pub package

Wraps platform-specific persistent storage for simple data (NSUserDefaults on iOS and macOS, SharedPreferences on Android, etc.). Data may be persisted to disk asynchronously, and there is no guarantee that writes will be persisted to disk after returning, so this plugin must not be used for storing critical data.

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);
0
likes
120
pub points
0%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, meta, shared_preferences_linux, shared_preferences_macos, shared_preferences_platform_interface, shared_preferences_web, shared_preferences_windows

More

Packages that depend on shared_preferences_hhz