Skip to content

Commit 3e1d028

Browse files
committed
Only setup the state change handler if we want the webview to be initially hidden
1 parent 6b922b6 commit 3e1d028

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/src/webview_scaffold.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class WebviewScaffold extends StatefulWidget {
4242
this.withLocalStorage,
4343
this.withLocalUrl,
4444
this.scrollBar,
45-
this.hidden : false,
45+
this.hidden = false,
4646
this.initialChild})
4747
: super(key: key);
4848

@@ -61,18 +61,22 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
6161
super.initState();
6262
webviewReference.close();
6363

64-
_onStateChanged = webviewReference.onStateChanged.listen((WebViewStateChanged state) {
65-
if (state.type == WebViewState.finishLoad) {
66-
webviewReference.show();
67-
}
68-
});
64+
if (widget.hidden) {
65+
_onStateChanged = webviewReference.onStateChanged.listen((WebViewStateChanged state) {
66+
if (state.type == WebViewState.finishLoad) {
67+
webviewReference.show();
68+
}
69+
});
70+
}
6971
}
7072

7173
@override
7274
void dispose() {
7375
super.dispose();
7476
webviewReference.close();
75-
_onStateChanged.cancel();
77+
if (widget.hidden) {
78+
_onStateChanged.cancel();
79+
}
7680
webviewReference.dispose();
7781
}
7882

@@ -116,20 +120,17 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
116120

117121
final mediaQuery = MediaQuery.of(context);
118122
final topPadding = widget.primary ? mediaQuery.padding.top : 0.0;
119-
final top =
120-
fullscreen ? 0.0 : widget.appBar.preferredSize.height + topPadding;
123+
final top = fullscreen ? 0.0 : widget.appBar.preferredSize.height + topPadding;
121124

122125
var height = mediaQuery.size.height - top;
123126

124127
if (widget.bottomNavigationBar != null) {
125128
height -= 56.0 +
126-
mediaQuery.padding
127-
.bottom; // todo(lejard_h) find a way to determine bottomNavigationBar programmatically
129+
mediaQuery.padding.bottom; // todo(lejard_h) find a way to determine bottomNavigationBar programmatically
128130
}
129131

130132
if (widget.persistentFooterButtons != null) {
131-
height -=
132-
53.0; // todo(lejard_h) find a way to determine persistentFooterButtons programmatically
133+
height -= 53.0; // todo(lejard_h) find a way to determine persistentFooterButtons programmatically
133134
if (widget.bottomNavigationBar == null) {
134135
height -= mediaQuery.padding.bottom;
135136
}

0 commit comments

Comments
 (0)