gpt4 book ai didi

flutter - flutter 的 child 内部验证错误

转载 作者:行者123 更新时间:2023-12-03 04:55:29 24 4
gpt4 key购买 nike

我试图在自己的 child 中做一个自我,但是如果我在烦躁的 child 中犯错,这就会给我一个错误。
我究竟做错了什么?

我想做的是:

if(snapshot.data.Facebook != null){
// display the image if different from null
Image.asset("assets/images/facebook.png",height: 40,), SizedBox(width: 10),
}

我的代码:----------------------------------------------- -----------
Padding(
padding: EdgeInsets.only(top: 50),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [

if(snapshot.data.Facebook != null){

};


Image.asset("assets/images/facebook.png",height: 40,), SizedBox(width: 10),

Image.asset("assets/images/instagram.png", height: 40,), SizedBox(width: 10),

Image.asset("assets/images/linkdin.png", height: 40,), SizedBox(width: 10),

Image.asset("assets/images/pinterest.png", height: 40,), SizedBox(width: 10),

Image.asset("assets/images/skype.png", height: 40,), SizedBox(width: 10),

Image.asset("assets/images/twitter.png", height: 40,), SizedBox(width: 10),

Image.asset("assets/images/whatsapp.png", height: 40,), SizedBox(width: 10),
],
),
)

enter image description here

最佳答案

这是小部件内部if / else的版本。如果条件为真,将显示?前面的小部件,而:为假条件。

Padding(
padding: EdgeInsets.only(top: 50),
child: snapshot.data.Facebook != null //check the condition
//return Row with images in it if snapshot.data.Facebook != null is true
? Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Image.asset(
"assets/images/facebook.png",
height: 40,
),
SizedBox(width: 10),
Image.asset(
"assets/images/instagram.png",
height: 40,
),
SizedBox(width: 10),
Image.asset(
"assets/images/linkdin.png",
height: 40,
),
SizedBox(width: 10),
Image.asset(
"assets/images/pinterest.png",
height: 40,
),
SizedBox(width: 10),
Image.asset(
"assets/images/skype.png",
height: 40,
),
SizedBox(width: 10),
Image.asset(
"assets/images/twitter.png",
height: 40,),
SizedBox(width: 10),
Image.asset(
"assets/images/whatsapp.png",
height: 40,
),
SizedBox(width: 10),
],
)
//return empty Row if snapshot.data.Facebook != null is false
: Row(
children: <Widget>[
//you can add more widget in here
],
)
)

关于flutter - flutter 的 child 内部验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60692943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com