please a error when I try to reload my webview from a button : E/flutter (18150): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Null check operator used on a null value
JavaScript
x
6
1
RaisedButton(
2
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 30),
3
onPressed: () async {
4
controller.reload();
5
},
6
this is my WebView
JavaScript
1
23
23
1
WebView(
2
initialUrl: "https://wikoget.com",
3
javascriptMode: JavascriptMode.unrestricted,
4
onWebViewCreated: (controller){
5
this.controller=controller;
6
},
7
onPageFinished: (String url) {
8
controller
9
.evaluateJavascript("javascript:(function() { " +
10
"var head = document.getElementsByClassName('main-header-bar-wrap')[0];" +
11
"head.parentNode.style.cssText = ' position: sticky;position: -webkit-sticky; top : 0 ';" +
12
"var footer = document.getElementsByTagName('footer')[0];" +
13
"footer.parentNode.removeChild(footer);" +
14
"})()")
15
.then((value) => debugPrint('Page finished loading Javascript'));
16
},
17
onWebResourceError: (error) => setState(() {
18
controller.loadUrl("about:blank");
19
isError = true;
20
}),
21
gestureNavigationEnabled: true,
22
),
23
Advertisement
Answer
enter code hereUse the fallback operator to set a default value for null values before using the variable.
JavaScript
1
4
1
String? str; //nullable value
2
str ??= "Fallback Value";
3
print(str); //Output: Fallback Value
4
Here, “str” is null, and we set the fallback operator with fallback value in case of “str” is null.