Skip to content

Commit

Permalink
Adds 'hiddenUntilFinishLoad' param
Browse files Browse the repository at this point in the history
This param is true by default, so it does not change the current behaviour: a hidden webview is automatically revealed once stateChanged.finishLoad is received.

It can be set to false so that a hidden webview is not automatically revealed when the page has finished loading.

This way, the user can keep the webview hidden as long as required (i.e. to wait for custom javascript evaluation after the page finishes loading).
  • Loading branch information
pmoreno-allica committed Jun 22, 2020
1 parent 4862bd9 commit 320b63b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class FlutterWebviewPlugin {
/// - [clearCache] clear the cache of the Webview
/// - [clearCookies] clear all cookies of the Webview
/// - [hidden] not show
/// - [hiddenUntilFinishLoad] stay hidden until finishLoad event
/// - [rect]: show in rect, fullscreen if null
/// - [enableAppScheme]: false will enable all schemes, true only for httt/https/about
/// android: Not implemented yet
Expand Down Expand Up @@ -150,6 +151,7 @@ class FlutterWebviewPlugin {
bool clearCookies,
bool mediaPlaybackRequiresUserGesture,
bool hidden,
bool hiddenUntilFinishLoad,
bool enableAppScheme,
Rect rect,
String userAgent,
Expand All @@ -174,6 +176,7 @@ class FlutterWebviewPlugin {
'withJavascript': withJavascript ?? true,
'clearCache': clearCache ?? false,
'hidden': hidden ?? false,
'hiddenUntilFinishLoad': hiddenUntilFinishLoad ?? true,
'clearCookies': clearCookies ?? false,
'mediaPlaybackRequiresUserGesture': mediaPlaybackRequiresUserGesture ?? true,
'enableAppScheme': enableAppScheme ?? true,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/webview_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class WebviewScaffold extends StatefulWidget {
this.supportMultipleWindows,
this.appCacheEnabled,
this.hidden = false,
this.hiddenUntilFinishLoad = true,
this.initialChild,
this.allowFileURLs,
this.resizeToAvoidBottomInset = false,
Expand Down Expand Up @@ -65,6 +66,7 @@ class WebviewScaffold extends StatefulWidget {
final bool supportMultipleWindows;
final bool appCacheEnabled;
final bool hidden;
final bool hiddenUntilFinishLoad;
final Widget initialChild;
final bool allowFileURLs;
final bool resizeToAvoidBottomInset;
Expand Down Expand Up @@ -110,7 +112,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
}
});

if (widget.hidden) {
if (widget.hidden && widget.hiddenUntilFinishLoad) {
_onStateChanged =
webviewReference.onStateChanged.listen((WebViewStateChanged state) {
if (state.type == WebViewState.finishLoad) {
Expand All @@ -136,9 +138,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
_onBack?.cancel();
_resizeTimer?.cancel();
webviewReference.close();
if (widget.hidden) {
_onStateChanged.cancel();
}
_onStateChanged?.cancel();
webviewReference.dispose();
}

Expand Down

0 comments on commit 320b63b

Please sign in to comment.