123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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('');
- }
- }
|