1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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<HomePage> {
- bool _isLoading = true;
- @override
- Widget build(BuildContext context) {
- return Stack(
- children: <Widget>[
- 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('');
- }
- }
|