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));
        }
      });
    }
    今ならできます。
  • 相关阅读:
    Python基础学习Day2
    Python基础学习
    字符串
    function对象
    GCN入门理解
    L1、L2正则化详解
    Matplotlib数据可视化基础
    sklearn 中模型保存的两种方法
    一文弄懂神经网络中的反向传播法——BackPropagation
    seaborn可视化
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/shared_preferences.html
Copyright © 2011-2022 走看看