zoukankan      html  css  js  c++  java
  • flutter 插件调用callback函数

    dart plugin

    class TestLib {
      static MethodChannel _channel = const MethodChannel('test_lib')
        ..setMethodCallHandler(_methodCallHandler);
    
      static Function _cb;
    
      static Future<void> _methodCallHandler(MethodCall call) async {
        printf("[%s], args: %o", call.method, call.arguments);
        switch (call.method) {
          case 'callListener':
            if(_cb != null) _cb(call.arguments as String);
            break;
          default:
            print('not method.');
        }
      }
    
      static void platformVersion(Function cb) {
        _cb = cb;
        _channel.invokeMethod('getPlatformVersion');
      }
    }
    

    kt

      override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
        if (call.method == "getPlatformVersion") {
          // result.success("Android ${android.os.Build.VERSION.RELEASE}")
          channel.invokeMethod("callListener", "Ajanuw");
        } else {
          result.notImplemented()
        }
      }
    

    use

    TestLib.platformVersion((String name) {
      print('hello $name');
    })
    
  • 相关阅读:
    160726 smarty 笔记(2)
    160726 smarty 笔记(1)
    smarty内置函数
    smarty变量调节器
    smarty基础原理
    【Django】:基础
    【十八章】:Web框架
    汇总
    jQuery
    DOM
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13843066.html
Copyright © 2011-2022 走看看