Reputation: 193
I'm developing a Flutter app, and I am trying to create a InAppWebView. Everything is working well on Android, but on iOS i got an error:
"Column's children must not contain any null values, but a null value was found at index 0".
I already hit flutter clean, flutter build ios, and clean xcode. But still got this error.
Any help is appreciated
Here is my code:
child: Scaffold(
appBar: AppBar(title: Text("voucherweb")),
body: Container(
child: Column(children: <Widget>[
progress == null ? Container() : (progress != 1.0)
? LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
: null,
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://voucherweb.com",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
useShouldOverrideUrlLoading: true),
),
shouldOverrideUrlLoading: (controller, request) async {
var url = request.url;
var uri = Uri.parse(url);
if (request.url.startsWith("https://wa.me/")) {
final newString =
url.replaceAll("https://wa.me/", "");
if (await canLaunch(url)) {
FlutterOpenWhatsapp.sendSingleMessage(
newString, "Halo, gan. Mau order voucher : ");
return ShouldOverrideUrlLoadingAction.CANCEL;
}
}
return ShouldOverrideUrlLoadingAction.ALLOW;
},
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart:
(InAppWebViewController controller, String url) {},
onLoadStop:
(InAppWebViewController controller, String url) {},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
this.progress = progress / 100;
});
}),
),
),
]))));
Upvotes: 0
Views: 1333
Reputation: 909
progress == null ? Container() : (progress != 1.0)
? LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
: Container(),
Please use this code null is not widget that's why you are getting this error.
Upvotes: 1
Reputation: 14043
You are setting one of the Column's
child to null
, consider using a SizedBox()
or a Container()
instead:
I added an example using your code:
child: Scaffold(
appBar: AppBar(title: Text("voucherweb")),
body: Container(
child: Column(children: <Widget>[
progress == null ? Container() : (progress != 1.0)
? LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
// new line
: SizedBox(),
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://voucherweb.com",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
useShouldOverrideUrlLoading: true),
),
shouldOverrideUrlLoading: (controller, request) async {
var url = request.url;
var uri = Uri.parse(url);
if (request.url.startsWith("https://wa.me/")) {
final newString =
url.replaceAll("https://wa.me/", "");
if (await canLaunch(url)) {
FlutterOpenWhatsapp.sendSingleMessage(
newString, "Halo, gan. Mau order voucher : ");
return ShouldOverrideUrlLoadingAction.CANCEL;
}
}
return ShouldOverrideUrlLoadingAction.ALLOW;
},
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart:
(InAppWebViewController controller, String url) {},
onLoadStop:
(InAppWebViewController controller, String url) {},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
this.progress = progress / 100;
});
}),
),
),
]))));
Upvotes: 3