在flutter中使用shared_preferences时如何处理这种类型的异常

时间:2019-12-11 13:26:15

标签: flutter-test

I / flutter(5320):发现异常:: MissingPluginException(未在通道plugins.flutter.io/shared_preferences上找到方法getAll的实现)

1 个答案:

答案 0 :(得分:0)

此问题存在https://github.com/flutter/flutter/issues/38873https://github.com/flutter/flutter/issues/29356

您可以使用0.5.3+1

shared_preferences: 0.5.3+1

我已经对其进行了测试,没有错误
完整的测试代码

导入'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);
}