vs_flutter_cordova

cordova在flutter上面的实现。

使用方法

引入依赖库

dependencies:
  vs_flutter_cordova: ^0.0.1

实现自己的插件

class VSBasePlugin extends CDVPlugin{

  @override
  String className() {
    return "base";
  }
  @override
  void invokeMethod(String methodName, List arguments, String callbackId) {
    Map echo = {"methodName": methodName, "arguments":arguments, "callbackId":callbackId};
    CDVPluginResult result = CDVPluginResult(CDVCommandStatus.ok,echo);
    //处理返回值
    sendPluginResult(result, callbackId);
  }
}

在webview_flutter中使用


class _WebViewExampleState extends State<WebViewExample> {
  //1)实例化
  final CDVController _cdvController = CDVController();
  @override
  Widget build(BuildContext context) {
    VSBasePlugin basePlugin = VSBasePlugin();
    _cdvController.addPlugins([basePlugin]);
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter WebView example'),
      ),
      body: Builder(builder: (BuildContext context) {
        return WebView(
          initialUrl: 'http://baiddu.com',
          javascriptMode: JavascriptMode.unrestricted,
          onWebViewCreated: (WebViewController webViewController) {
            //3)持有webViewController
            _cdvController.webViewController = webViewController;
          },
          javascriptChannels:
              <JavascriptChannel>[_cdvController.javascriptChannel].toSet(), //2)建立通道
        );
      }),
    );
  }
}

Libraries

cdv_command
cdv_controller
cdv_plugin
cdv_plugin_result
vs_flutter_cordova