Skip to content

Commit eab2780

Browse files
committed
增加测试代码
1 parent 5ca97ef commit eab2780

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

lib/page/gsy_webview.dart

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:flutter/cupertino.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
@@ -27,26 +29,72 @@ class GSYWebView extends StatelessWidget {
2729
]);
2830
}
2931

32+
final FocusNode focusNode = new FocusNode();
3033
@override
3134
Widget build(BuildContext context) {
32-
3335
/*return Scaffold(
3436
appBar: new AppBar(
3537
title: _renderTitle(),
3638
),
37-
body: WebView(
38-
initialUrl: url,
39-
javascriptMode: JavascriptMode.unrestricted,
39+
body: new Stack(
40+
children: <Widget>[
41+
TextField(
42+
focusNode: focusNode,
43+
),
44+
WebView(
45+
initialUrl: new Uri.dataFromString(html, mimeType: 'text/html', encoding: Encoding.getByName("utf-8")).toString(),
46+
javascriptMode: JavascriptMode.unrestricted,
47+
javascriptChannels: Set.from([
48+
JavascriptChannel(
49+
name: 'Print',
50+
onMessageReceived: (JavascriptMessage message) {
51+
print("FFFFFF");
52+
print(message.message);
53+
FocusScope.of(context).requestFocus(focusNode);
54+
})
55+
]))
56+
],
4057
),
4158
);*/
4259
return new WebviewScaffold(
4360
withJavascript: true,
4461
url: url,
45-
scrollBar:true,
62+
scrollBar: true,
4663
withLocalUrl: true,
4764
appBar: new AppBar(
4865
title: _renderTitle(),
4966
),
5067
);
5168
}
5269
}
70+
71+
72+
///测试 html 代码,不管
73+
final testhtml = "<!DOCTYPE html>"
74+
"<html>"
75+
"<head>"
76+
"<meta charset=\"utf-8\">"
77+
"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\" />"
78+
"<title>Local Title</title>"
79+
"<script>"
80+
"function callJS(){"
81+
"alert(\"Android调用了web js\");"
82+
"}"
83+
"function callInterface(){"
84+
"JSCallBackInterface.callback(\"我是web的js哟\");"
85+
"}"
86+
"function callInterface2(){"
87+
"document.location = \"js://Authority?pra1=111&pra2=222\";"
88+
"}"
89+
"function clickPrompt(){"
90+
"Print.postMessage('Hello');"
91+
"}"
92+
"</script>"
93+
"</head>"
94+
"<body>"
95+
"<button type=\"button\" id=\"buttonxx\" onclick=\"callInterface()\">点我调用原生android方法</button>"
96+
"<button type=\"button\" id=\"buttonxx2\" onclick=\"callInterface2()\">点我调用原生android方法2</button>"
97+
"<button type=\"button\" id=\"buttonxx3\" onclick=\"clickPrompt()\">点我调用原生android方法3</button>"
98+
"<input></input>"
99+
"</body>"
100+
"</html>";

0 commit comments

Comments
 (0)