この問題を解決する方法はありますか?
スタックトレース:
[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<…>
ベストアンサー1
この問題は、Flutter をアップグレードすると発生します。その原因は、何らかのデータを待機しているか、async
内部で関数を実行していることにありますmain()
。
ScopedModel
内部で初期化を行っておりmain()
、内部で何らかのデータを待っていました。
非常に小さな修正方法があります。を実行する前に、WidgetsFlutterBinding.ensureInitialized()
の内部を実行するだけです。 うまく機能します!!void main()
runApp()
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(Delta(
model: ProductDataModel(),
));
}