[英]Column's children must not contain any null values, but null value was found at index 0
我正在開發一個 Flutter 應用程序,並且我正在嘗試創建一個 InAppWebView。 在 Android 上一切正常,但在 iOS 上出現錯誤:
“列的子項不得包含任何 null 值,但在索引 0 處找到 null 值”。
我已經打了 flutter 清潔,flutter 構建 ios,清潔 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, String url) {},
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, String url) {},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
this.progress = progress / 100;
});
}),
),
),
]))));
progress == null ? Container() : (progress != 1.0)
? LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
: Container(),
請使用此代碼 null 不是小部件,這就是您收到此錯誤的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.