zoukankan      html  css  js  c++  java
  • fluterr shared_preferences 存储用户信息 MissingPluginException(No implementation found for method getAll on channel

     环境:

    flutter  [√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19042.1110], locale zh-CN)

    dependencies

    # 数据存储  登录信息
    shared_preferences: ^2.0.6

    example示例   https://pub.flutter-io.cn/packages/shared_preferences/example

    import 'package:shared_preferences/shared_preferences.dart';
    Future<SharedPreferences> _prefs = SharedPreferences.getInstance();

    但是直接使用就会出现错误:

    MissingPluginException(No implementation found for method getAll on channel

    需要在main函数增加  SharedPreferences.setMockInitialValues({});   // 处理报错

    import 'package:shared_preferences/shared_preferences.dart';
    
    void main() {
      SharedPreferences.setMockInitialValues({});   // 处理报错
      Store<AppState> store = new Store<AppState>(mainReducer,
          initialState: new AppState(
            auth: new AuthState(),
          ));
    
    //  Global.init().then((e) => runApp(MyApp(store: store)));
    //  Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
      WidgetsFlutterBinding.ensureInitialized(); //解决加载json错误
      Global.init().then((dynamic res) {
        print(res);
        if (res == 'ok') {
          $Api.dioUtil = DioUtil(); //实例化dio
          runApp(MyApp(store: store));
        }
      });
    }
    今ならできます。
  • 相关阅读:
    打印出1-10000之间的所有对称数(如121,1331,2442)
    代码块
    javascript判断数据类型
    块和内嵌
    xhtml+css基础知识2
    xhtml+css基础知识1
    清除浮动
    margin注意问题
    javascirpt 闭包
    css3 box-sizing属性
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/shared_preferences.html
Copyright © 2011-2022 走看看