如何解决列的子级不能包含任何空值,但是在索引0处找到了空值
我正在开发Flutter应用,并且正在尝试创建InAppWebView。在Android上一切正常,但在iOS上却出现错误:
“列的子级不能包含任何空值,但是在索引0处找到了空值”。
我已经完成了flutter clean,flutter build ios和clean xcode。但是仍然出现此错误。
感谢您的帮助
这是我的代码:
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,onProgressChanged:
(InAppWebViewController controller,int progress) {
setState(() {
this.progress = progress / 100;
});
}),]))));
解决方法
您要将Column's
子级之一设为null
,请考虑改用SizedBox()
或Container()
:
我使用您的代码添加了一个示例:
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,onProgressChanged:
(InAppWebViewController controller,int progress) {
setState(() {
this.progress = progress / 100;
});
}),]))));
,
progress == null ? Container() : (progress != 1.0)
? LinearProgressIndicator(
value: progress,valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
: Container(),
请使用此代码null不是小部件,这就是为什么您会收到此错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。