Skip to content

Instantly share code, notes, and snippets.

@vreamer
Last active August 26, 2020 08:42
Show Gist options
  • Save vreamer/acc15439fac9e2d6940ce2fb20482ffa to your computer and use it in GitHub Desktop.
Save vreamer/acc15439fac9e2d6940ce2fb20482ffa to your computer and use it in GitHub Desktop.
import 'package:direct_reply_notification/data-service.dart';
import 'package:flutter/services.dart';
class FlutterMethodChannel {
static const channelName = 'channel';
MethodChannel methodChannel;
static final FlutterMethodChannel instance = FlutterMethodChannel._init();
FlutterMethodChannel._init();
void configureChannel() {
methodChannel = MethodChannel(channelName);
methodChannel.setMethodCallHandler(this.methodHandler); // set method handler
}
Future<void> methodHandler(MethodCall call) async {
final String idea = call.arguments;
switch (call.method) {
case "showNewIdea": // this method name needs to be the same from invokeMethod in Android
DataService.instance.addIdea(idea); // you can handle the data here. In this example, we will simply update the view via a data service
break;
default:
print('no method handler for method ${call.method}');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment