-
Notifications
You must be signed in to change notification settings - Fork 939
Closed
Labels
Description
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);
}
}