【问题标题】:if condition to run Widget at Container flutter如果条件在容器颤振中运行小部件
【发布时间】:2019-12-29 23:18:22
【问题描述】:

如果 post.text == 1 时的条件 我设置了名为 externews 的小部件

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

      }

如果与该容器一起使用,如何使用

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

我设置String checkothers = post.text; 我读到我必须设置小部件才能使用运行 exteranews() 但如何使用它的 if 条件

【问题讨论】:

标签: flutter


【解决方案1】:
  1. 您可以使用? 语法
  2. 请确保输入Container(),这样它就不会显示任何内容 更容易将 Container() 映射为 html 中的 <div></div>
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(),
    );
  }
}

【讨论】:

  • 谢谢,非常有帮助
猜你喜欢
  • 1970-01-01
  • 2021-10-22
  • 2019-07-10
  • 2023-03-07
  • 2018-09-18
  • 2021-09-02
  • 2021-06-11
  • 2018-10-18
  • 2022-10-14
相关资源
最近更新 更多