首页 > 解决方案 > 流式传输数据时如何通过小部件构建条件?

问题描述

我正在将集合作为快照从 Firestore 流式传输到我的颤振项目。当集合中不存在变量 im 循环时,我如何在文本小部件中写入,例如“空”?

child: Column(     
    children: <Widget>[
      if (title != null)
        {
          Text(
            title,
            ),
          ),
        }
      else {
        Text('empty'),

标签: fluttertextdartgoogle-cloud-firestore

解决方案


您可以使用如下代码:-

String title = '';
return Container(
      child: Column(
        children: <Widget>[
          Text(title.isNotEmpty ? title : 'empty')
        ],
      ),
);

推荐阅读