0

In my project , my flutter module need to fetch some information from native with MethodChannel.

And I want this method channel call is returned before even the root widget display (because this widget will use this information to fetch data and display)

I have tried invoking before runApp in main(). but this call seems too early to work . And I don't know whether is a bad idea to make main async

Any other better way to do this kind of work?

    void main() async{
      WidgetsFlutterBinding.ensureInitialized();
      MethodChannel platform = const MethodChannel('flutter.km.methodchannel');
      var nativeInfo = await platform.invokeMethod('getNativeInfo');
      runApp(const MyApp());
    }
ximmyxiao
  • 2,622
  • 3
  • 20
  • 35

1 Answers1

0

There is no problem with your use of async-await. This question on stackoverflow has detailed information in the link below. please look there.

Good or Bad: Declaring main method async in Dart / Flutter

Alakba
  • 178
  • 10