gpt4 book ai didi

flutter - if condition to run Widget at Container flutter

转载 作者:IT王子 更新时间:2023-10-29 07:15:02 26 4
gpt4 key购买 nike

if 条件 when post.text == 1我设置了名为 exteranews 的小部件

  Widget exteranews(BuildContext context) {
double siz11 = 15.0 * MediaQuery.of(context).size.width / 414.0;

}

如何在容器中使用 if

 Container(
if (checkothers) child: exteranews(context),
),

我设置 String checkothers = post.text;我读到我必须设置 Widget 才能使用 run exteranews() 但是如何使用 if 条件

最佳答案

  1. 您可以使用 ?句法
  2. 请确保输入Container()所以它什么也不会显示更容易想象 Container() 等于 <div></div>在 HTML 中
Widget extraNews(BuildContext context) {
double siz11 = 15.0 * MediaQuery.of(context).size.width / 414.0;
return Container();
}

class BaseScreen extends StatelessWidget {
///
@override
Widget build(BuildContext context) {
return Container(
child: checkothers == true ? extraNews(context) : Container(),
);
}
}

关于flutter - if condition to run Widget at Container flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57646489/

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