4

something wrong with my code, I want send message to Flutter.

static const channel = MethodChannel('foo');

channel.setMethodCallHandler((MethodCall call) async {
  switch (call.method) {
    case 'bar':
      return 'Hello, ${call.arguments}';
    default:
      throw MissingPluginException();
  }
});

enter image description here

G.daogeng
  • 51
  • 1
  • 5
  • Your question is a bit vague. Do you need the implementation for iOS or Flutter side? Secondly did you check this link https://flutter.io/docs/development/platform-integration/platform-channels ? – salihgueler Feb 01 '19 at 08:38
  • See the linked answer. If you still have problems, update the question with more of the code (including the imports). – Richard Heap Feb 01 '19 at 19:48
  • static const _channel = const MethodChannel('samples.flutter.io/battery'); _channel.setMethodCallHandler(myUtilsHandler); there is an error prompt with _channel; "Invalid constructor name.dart(invalid_constructor_name)" – G.daogeng Feb 02 '19 at 02:16
  • When I move "_channel.setMethodCallHandler(myUtilsHandler);" in initState method, It work. – G.daogeng Feb 02 '19 at 02:27

0 Answers0