github地址
歡迎加入QQ群883130953 有問題一起討論
功能說明
Android 已實現(xiàn)橋接 視頻播放 相冊打開
Ios只支持普通的頁面顯示
1. webview初始化
///注意: 需要首先授權(quán)存儲權(quán)限 否則 X5內(nèi)核加載失敗
X5Plugin.init().then((isOk) {
x5Init = isOk;
print(isOk ? "X5內(nèi)核成功加載" : "X5內(nèi)核加載失敗");
});
2.提供了三種方式 一般建議第三種
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: () {
X5Plugin.openFilechooserActivity("file:///android_asset/webpage/fileChooser.html",
title: "xx");
},
child: Container(
child: Text("支持打開相冊頁面 支持視頻 不支持橋接"),
width: 150,
height: 150,
color: Colors.red,
),
),
SizedBox(height: 30,),
GestureDetector(
onTap: () {
X5Plugin.openWebActivity("https://www.youku.com/", title: "xx");
},
child: Container(
child: Text("支持視頻 不支持橋接和相冊"),
width: 150,
height: 150,
color: Colors.red,
),
),
SizedBox(height: 30,),
GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new Demo("file:///android_asset/webpage/demo.html")),
);
},
child: Container(
child: Text("支持 橋接 視頻 不支持相冊(一般建議用這個 這個實用)"),
width: 150,
height: 150,
color: Colors.red,
),
),
],
),
);
}
}
3.一般建議這種方式
class Demo extends StatefulWidget {
String url;
Demo(this.url);
@override
_DemoState createState() => _DemoState();
}
class _DemoState extends State<Demo> {
X5WebViewController _controller;
@override
Widget build(BuildContext context) {
return Scaffold (
appBar: AppBar(
title: Text("webview實例")),
body: X5Webview(url: widget.url,
onPageFinished: (String url) async{
///橋接名字
var listName = ["X5Web"];
_controller.addJavascriptChannels(listName,
(name, data) {
switch (name) {
case "X5Web":
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("獲取到的字符串為:"),
content: Text(data),
);
});
break;
case "Toast":
print(data);
break;
}
});
},
onWebViewCreated:(X5WebViewController controller) {
_controller = controller;
} ,)
);
}
}