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

outdatedDart 1 only

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

shared_preferences #

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

Publisher

verified publisherflutter.dev

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on shared_preferences