Created
November 3, 2019 11:06
-
-
Save robertohuertasm/d83b5f19dc24786da68e3f9b24c04d53 to your computer and use it in GitHub Desktop.
rust_for_android_ios_flutter
This file contains hidden or 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
package com.robertohuertas.rusty_flutter_lib | |
// importing the Android library | |
import com.robertohuertas.rusty_android_lib.* | |
import io.flutter.plugin.common.MethodCall | |
import io.flutter.plugin.common.MethodChannel | |
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | |
import io.flutter.plugin.common.MethodChannel.Result | |
import io.flutter.plugin.common.PluginRegistry.Registrar | |
class RustyFlutterLibPlugin: MethodCallHandler { | |
companion object { | |
@JvmStatic | |
fun registerWith(registrar: Registrar) { | |
val channel = MethodChannel(registrar.messenger(), "rusty_flutter_lib") | |
channel.setMethodCallHandler(RustyFlutterLibPlugin()) | |
// dynamically loading the android library | |
loadRustyLib() | |
} | |
} | |
override fun onMethodCall(call: MethodCall, result: Result) { | |
when { | |
call.method == "getPlatformVersion" -> result.success("Android ${android.os.Build.VERSION.RELEASE}") | |
call.method == "getHello" -> { | |
val to = call.argument<String>("to") | |
if (to == null) { | |
result.success("No to parameter found") | |
} else { | |
// we're using the helloDirect function here | |
// but you could also use the hello function, too. | |
val res = helloDirect(to) | |
result.success(res) | |
} | |
} | |
else -> result.notImplemented() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment