gpt4 book ai didi

flutter : How can I show no widget with no space taking when there's no link?

转载 作者:行者123 更新时间:2023-12-02 02:24:45 26 4
gpt4 key购买 nike

代码说明:我检查是否有指向 youtube 的链接,然后显示 youtube 的图标,否则不显示任何内容。

问题:但在下面的代码中,我添加了一个空容器(),但该容器在我的行中占据了位置。

Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Row(
children: [

Text("Social Media : "),
],
),
),
_youtubelink == null
? Container()
: GestureDetector(
child: Icon(
FontAwesome5.youtube,
color: red,
),
onTap: () {
_launchURL(_youtubelink);
},
),
_istagramlink == null
? Container()
: GestureDetector(
child: Icon(
FontAwesome5.instagram,
color: red,
),
onTap: () {
_launchURL(_istagramlink);
},
),
_facebooklink == null
? Container()
: GestureDetector(
child:
Icon(FontAwesome5.facebook, color: blue),
onTap: () {
_launchURL(_facebooklink);
},
),
_twitterlink == null
? Container()
: GestureDetector(
child: Icon(FontAwesome5.twitter,
color: lightyellow),
onTap: () {
_launchURL(_twitterlink);
},
),
Container(), // to let a space between edge and icons
],
)

image when there's a link

image when there's a link

当没有链接时,如何显示不占用空间的小部件?谢谢

最佳答案

如果我的问题正确,您可以简单地将 if 放入列表中(collection if),而不是使用三元运算符来显示空容器的链接:

基本上,你的代码会变成这样:

Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Row(
children: [

Text("Social Media : "),
],
),
),
if(_youtubelink != null)
GestureDetector(
child: Icon(
FontAwesome5.youtube,
color: red,
),
onTap: () {
_launchURL(_youtubelink);
},
),
if(_istagramlink != null)
GestureDetector(
child: Icon(
FontAwesome5.instagram,
color: red,
),
onTap: () {
_launchURL(_istagramlink);
},
),
if(_facebooklink != null)
GestureDetector(
child:
Icon(FontAwesome5.facebook, color: blue),
onTap: () {
_launchURL(_facebooklink);
},
),
if(_twitterlink != null)
GestureDetector(
child: Icon(FontAwesome5.twitter,
color: lightyellow),
onTap: () {
_launchURL(_twitterlink);
},
),
Container(), // to let a space between edge and icons
],
)

您可以在 https://dart.dev/guides/language/language-tour#lists 中了解更多相关信息.

关于 flutter : How can I show no widget with no space taking when there's no link?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65864354/

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