home_page.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:flutter/material.dart';
  2. import 'package:webview_flutter/webview_flutter.dart';
  3. /// Description:
  4. /// Time : 2021年12月03日 Friday
  5. /// Author : liuyuqi.gov@msncn
  6. class HomePage extends StatefulWidget {
  7. String url;
  8. HomePage({Key key, this.url}) : super(key: key);
  9. @override
  10. _HomePageState createState() => _HomePageState();
  11. }
  12. class _HomePageState extends State<HomePage> {
  13. bool _isLoading = true;
  14. @override
  15. Widget build(BuildContext context) {
  16. return Stack(
  17. children: <Widget>[
  18. WebView(
  19. initialUrl: widget.url,
  20. javascriptMode: JavascriptMode.unrestricted,
  21. onWebViewCreated: (WebViewController web) {
  22. web.canGoBack().then((res) {
  23. // print(res); // 是否能返回上一级
  24. });
  25. web.currentUrl().then((url) {
  26. // print(url); // 返回当前url
  27. });
  28. web.canGoForward().then((res) {
  29. // print(res); //是否能前进
  30. });
  31. },
  32. onPageFinished: (String value) {
  33. // 返回当前url
  34. // print(value);
  35. setState(() {
  36. _isLoading = false;
  37. });
  38. },
  39. ),
  40. _loading()
  41. ],
  42. );
  43. }
  44. _loading() {
  45. return _isLoading == true
  46. ? Container(
  47. decoration: const BoxDecoration(color: Colors.white),
  48. child: const Center(
  49. child: CircularProgressIndicator(),
  50. ),
  51. )
  52. : const Text('');
  53. }
  54. }