Created
June 18, 2018 11:39
-
-
Save 0phelia/7e96707c21c73eb3d6ff8753bef16544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EventChannel(getFlutterView(), | |
CHANNEL_PLAYBACK_EVENTS, | |
JSONMethodCodec.INSTANCE) | |
.setStreamHandler( | |
object : EventChannel.StreamHandler { | |
override fun onListen(args: Any?, | |
events: EventChannel.EventSink) { | |
playbackEventSink = events | |
} | |
override fun onCancel(args: Any?) { | |
// free resources | |
} | |
}) | |
static const playbackEventChannel = const EventChannel('flutterify/playback', | |
const JSONMethodCodec()); | |
playbackEventChannel.receiveBroadcastStream() | |
.listen((meta) { | |
metadataCallback(meta); | |
}); | |
static const myMethodChannel = | |
const MethodChannel('methodChannelName'); | |
static Future<Null> callWithParams(String id) async { | |
try { | |
await myMethodChannel.invokeMethod('methodOne', {'id': id}); | |
} on PlatformException catch (e) { | |
print("${e.message}"); | |
} | |
} | |
static Future<Null> callWithoutParams() async{ | |
try { | |
await myMethodChannel.invokeMethod('methodTwo'); | |
} on PlatformException catch (e) { | |
print("${e.message}"); | |
} | |
} | |
MethodChannel(getFlutterView(), "methodChannelName") | |
.setMethodCallHandler(object : MethodCallHandler { | |
override fun onMethodCall(call: MethodCall, result: Result) { | |
if (call.method.equals("methodOne")) { | |
val myId: String = call.argument("id") | |
// do something on Android side | |
} else if (call.method.equals("methodTwo")) { | |
// do something on Android side | |
} else { | |
// error: method is not defined | |
} | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment