美文网首页Flutter开发圈
升级flutter1.9 运行老版本创建的项目报错

升级flutter1.9 运行老版本创建的项目报错

作者: 格雷s | 来源:发表于2019-09-25 10:08 被阅读0次

    升级flutter1.9之后运行老项目报以下错误:

    [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
    If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
    If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.
    #0      defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:73:7)
    #1      defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:86:4)
    #2      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62)
    #3      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:35)
    <asynchronous suspension>
    #4      MethodChannel.invokeMapMethod (package:f<…>
    
    

    其实,日志已经说的比较明白了,在main函数里,runApp()调用之前,手动调用WidgetsFlutterBinding.ensureInitialized

    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      runApp(MyApp());
    }
    

    相关文章

      网友评论

        本文标题:升级flutter1.9 运行老版本创建的项目报错

        本文链接:https://www.haomeiwen.com/subject/wjekuctx.html