vs_flutter_cordova 0.0.3

Flutter Android iOS

在flutter上面提供cordova的机制

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)建立通道
        );
      }),
    );
  }
}
0
likes
60
pub points
0%
popularity

在flutter上面提供cordova的机制

Homepage

Documentation

API reference

Uploader

mrs17951@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, webview_flutter

More

Packages that depend on vs_flutter_cordova