shared_preferences 0.2.3 copy "shared_preferences: ^0.2.3" to clipboard
shared_preferences: ^0.2.3 copied to clipboard

outdatedDart 1 only

A Flutter plugin for reading and writing simple key-value pairs.

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 automatically and asynchronously.

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(new MaterialApp(
    home: new Scaffold(
      body: new Center(
      child: new RaisedButton(
        onPressed: _incrementCounter,
        child: new Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  prefs.setInt('counter', counter);
}
9731
likes
0
pub points
100%
popularity

Publisher

verified publisherflutter.dev

A Flutter plugin for reading and writing simple key-value pairs.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on shared_preferences