facebook twitter hatena line email

「Flutter/外部ライブラリ/shared preferences」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(サンプル)
(サンプル)
行13: 行13:
 
<pre>
 
<pre>
 
import 'package:shared_preferences/shared_preferences.dart';
 
import 'package:shared_preferences/shared_preferences.dart';
 +
 +
 +
      floatingActionButton: FloatingActionButton(
 +
        onPressed: _incrementCounter,
 +
        tooltip: 'Increment',
 +
        child: Icon(Icons.add),
 +
      ), // This trailing comma makes auto-formatting nicer for build methods.
 +
 
_incrementCounter() async {
 
_incrementCounter() async {
 
   SharedPreferences prefs = await SharedPreferences.getInstance();
 
   SharedPreferences prefs = await SharedPreferences.getInstance();

2019年4月26日 (金) 17:57時点における版

shared_preferencesをインストール

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.5.2

flutter packages get

サンプル

import 'package:shared_preferences/shared_preferences.dart';


      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.

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

参考

公式:https://pub.dartlang.org/packages/shared_preferences

https://qiita.com/superman9387/items/4786ba4208a546842176