admin
2021-12-03 f092e392700f68cdbfc545c9801f530d19fd39fa
lib/ui/common/browser.dart
@@ -4,20 +4,26 @@
import 'package:flutter/material.dart';
import 'package:locations/ui/widget/nav.dart';
import 'package:locations/utils/jsinterface.dart';
import 'package:locations/utils/string_util.dart';
import 'package:webview_flutter/webview_flutter.dart';
class BrowserPage extends StatefulWidget {
  BrowserPage({Key? key, required this.title}) : super(key: key);
  BrowserPage({Key? key, required this.title, required this.url})
      : super(key: key);
  final String title;
  final String url;
  @override
  _BrowserPageState createState() => _BrowserPageState();
  _BrowserPageState createState() => _BrowserPageState(title, url);
}
class _BrowserPageState extends State<BrowserPage>
    with SingleTickerProviderStateMixin {
  String title = "";
  String? url;
  double progress = 0;
  _BrowserPageState(this.title, this.url);
  @override
  void initState() {
@@ -41,19 +47,22 @@
              height: 1,
              child: LinearProgressIndicator(
                backgroundColor: Colors.white,
                valueColor: AlwaysStoppedAnimation(Color(0xFF0E96FF)),
                valueColor: const 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;
              //http://192.168.3.122:8848/test/JsTest.html
              initialUrl: "http://192.168.3.122:8848/base/JsTest.html",
              onWebViewCreated: (WebViewController webViewController) {
                _webViewController = webViewController;
              },
              javascriptMode: JavascriptMode.unrestricted,
              javascriptChannels: JavascriptInterface(context,_webViewController).getInterfaces(),
              javascriptChannels:
                  JavascriptInterface(context, _webViewController)
                      .getInterfaces(),
              navigationDelegate: (NavigationRequest request) {
                print("链接:${request.url}");
                if (!request.url.startsWith("http")) {
@@ -66,6 +75,13 @@
              },
              onPageFinished: (url) {
                print("process:onPageFinished-$url");
                _webViewController!.getTitle().then((value) {
                  if (value != null) {
                    setState(() {
                      title = value;
                    });
                  }
                });
              },
              onProgress: (int process) {
                print("process:$process");