import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; /// Description: /// Time : 2021年12月03日 Friday /// Author : liuyuqi.gov@msncn class HomePage extends StatefulWidget { String url; HomePage({Key key, this.url}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { bool _isLoading = true; @override Widget build(BuildContext context) { return Stack( children: [ WebView( initialUrl: widget.url, javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (WebViewController web) { web.canGoBack().then((res) { // print(res); // 是否能返回上一级 }); web.currentUrl().then((url) { // print(url); // 返回当前url }); web.canGoForward().then((res) { // print(res); //是否能前进 }); }, onPageFinished: (String value) { // 返回当前url // print(value); setState(() { _isLoading = false; }); }, ), _loading() ], ); } _loading() { return _isLoading == true ? Container( decoration: const BoxDecoration(color: Colors.white), child: const Center( child: CircularProgressIndicator(), ), ) : const Text(''); } }