import 'dart:io';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:location/ui/widget/nav.dart';
|
import 'package:location/utils/jsinterface.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
class BrowserPage extends StatefulWidget {
|
BrowserPage({Key? key, required this.title}) : super(key: key);
|
final String title;
|
|
@override
|
_BrowserPageState createState() => _BrowserPageState();
|
}
|
|
class _BrowserPageState extends State<BrowserPage>
|
with SingleTickerProviderStateMixin {
|
String title = "";
|
double progress = 0;
|
|
@override
|
void initState() {
|
super.initState();
|
if (Platform.isAndroid) {
|
WebView.platform = SurfaceAndroidWebView();
|
}
|
}
|
|
WebViewController? _webViewController;
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Flex(
|
direction: Axis.vertical,
|
children: [
|
TopNavBar(title: title),
|
SizedBox(
|
height: 1,
|
child: LinearProgressIndicator(
|
backgroundColor: Colors.white,
|
valueColor: AlwaysStoppedAnimation(Color(0xFF0E96FF)),
|
value: progress,
|
),
|
),
|
Expanded(
|
child: WebView(
|
//http://192.168.3.122:8848/test/JsTest.html
|
initialUrl: 'http://192.168.3.122:8848/test/JsTest.html',
|
onWebViewCreated: (WebViewController webViewController){
|
_webViewController=webViewController;
|
},
|
javascriptMode: JavascriptMode.unrestricted,
|
javascriptChannels: JavascriptInterface(context,_webViewController).getInterfaces(),
|
navigationDelegate: (NavigationRequest request) {
|
print("链接:${request.url}");
|
if (!request.url.startsWith("http")) {
|
return NavigationDecision.prevent;
|
}
|
return NavigationDecision.navigate;
|
},
|
onPageStarted: (url) {
|
print("process:onPageStarted-$url");
|
},
|
onPageFinished: (url) {
|
print("process:onPageFinished-$url");
|
},
|
onProgress: (int process) {
|
print("process:$process");
|
setState(() {
|
if (process == 100) {
|
progress = 0;
|
} else {
|
progress = process / 100.0;
|
}
|
});
|
},
|
))
|
],
|
));
|
}
|
}
|