Find file History
dnfield Update gradle dependencies. (#881)
* update graddle-wrapper for all, update docs/example for AdMob

* Deprecate dart methods

* pubspec bump, CHANGELOG

* typo

* Use right deprecated annotation, add ignore

* update example to not use deprecated members

* const

* format!

* pin test for now

* pin mockito version to avoid breakage with test

* revert firebase changes

* update osx_instance

* high sierra
Latest commit 9b15392 Nov 3, 2018

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.


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


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

void main() {
    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);


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

const MethodChannel('')
  .setMockMethodCallHandler((MethodCall methodCall) async {
    if (methodCall.method == 'getAll') {
      return <String, dynamic>{}; // set initial values here if desired
    return null;