NaingMyoThawNMYT / Flutchat

Flutchat - integration of tokbox native SDK within flutter app

Home Page:https://blog.solutelabs.com/integrating-third-party-native-sdks-in-flutter-df418829dcf7

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flutchat

This sample is to describe method channel feature in practical aspect. (Complete steps in this blog) We will implement third party dependency provided by TokBox sdk and integrate it along with flutter. The main agenda for method channel is to use platform specific APIs in flutter.

Getting Started

Android

Requirements

  • You need to replace you api key, session id and token with yours here which you can get from OpenTok dashboard project section

Implementation

  • To integrate platform channel in android we need to initiate MehtodChannel in onCreate method in LauncherActivity (Here we will use FirstActivity as Launcher).
        MethodChannel(flutterView, "channel_id")
                .setMethodCallHandler { methodCall, result ->
                    methodCall.method?.let {
                        if (it.contentEquals("method")) {
                          // use result object to pass success or error event to main.dart
                          // the datatype of result will be MethodChannel.Result
                        }
                    }
                }

  • Then we need to invoke method from method channel from main.dart on respective events using following code snippet.
var output = await platform.invokeMethod("method");

Here output variable will get output of method call. It will wait for method execution.

  • To get acomplish method invocation call success or error method from MethodChannel.Result object which we retrive during method channel initialization.

  • We can get output value using result object which we get from MethodCallHandler provided in MethodChannel initialization in Launcher Activity.

result.success(any object);

For more information regarding platform channel refer online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

More reference

About

Flutchat - integration of tokbox native SDK within flutter app

https://blog.solutelabs.com/integrating-third-party-native-sdks-in-flutter-df418829dcf7


Languages

Language:Kotlin 67.8%Language:Swift 20.9%Language:Dart 10.1%Language:Ruby 1.0%Language:Objective-C 0.1%