home_page.dart 1.4 KB

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