您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何将控件动态添加到Flutter中的列?

如何将控件动态添加到Flutter中的列?

如果您已有评论数据,只需创建一个列表,然后将其传递到的children属性即可Column。就像是:

var commentWidgets = List<Widget>();
for (var comment in comments) {
  commentWidgets.Add(Text(comment.text)); // TODO: Whatever layout you need for each widget.
}
…

new Expanded(
      child:
      new ListView(
        shrinkWrap: true,
        children: <Widget>[

          // Title

          new Padding(padding: const EdgeInsets.only(
              top: 10.00, left: 10.00),
            child: new Text(
              _Feed.title, textAlign: TextAlign.start,),
          ),

          // content

          new Container(
            child: new Text(
              _Feed.content, textAlign: TextAlign.start,),
          ),

          // Comments List will go here
          Column(children: commentWidgets,),
        ],
      ),
    ),

如果您还没有注释数据,需要获取它,请在将来完成后使用FutureBuilder来构建UI。

其他 2022/1/1 18:21:26 有476人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶