Skip to content

The webview content shows loading indicator and nothing else #162

@baoxiehao

Description

@baoxiehao

Reproduce:

Open a webview and click a sublink, then go back will return to the original web page, then go back AGAIN, the webview will not be closed but just shows a loading indicator and blank page content.
And sometimes not clicking a sublink before going back will also causing this problem.

And if I fire the close() inside onWillPop will not be working also.

class WebViewWidget extends StatefulWidget {
  final String title;
  final String url;

  WebViewWidget({Key key, this.title, this.url}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _WebviewState();
}

class _WebviewState extends State<WebViewWidget> {

  final flutterWebviewPlugin = FlutterWebviewPlugin();

  String currentUrl;

  @override
  void initState() {
    flutterWebviewPlugin.onUrlChanged.listen((url) {
      print('url changed from $currentUrl to $url');
      currentUrl = url;
    });
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onWillPop,
      child: WebviewScaffold(
        url: widget.url,
        appBar: AppBar(
          title: Text(
            widget.title,
          ),
        ),
      ),
    );
  }

  Future<bool> _onWillPop() {
    flutterWebviewPlugin.close();
    return Future.value(currentUrl == widget.url);
  }
}

wechatimg54

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions