How to add the widgets dynamically to column in Flutter?

后端 未结 4 1026
日久生厌
日久生厌 2021-02-08 10:55

I have added a few widgets inside the ListView. So that I can scroll all widgets. Now I required to add one more widget to the ListView to load the li

4条回答
  •  醉话见心
    2021-02-08 11:35

    If you have the comments data already, simply create a List, then pass it to the children property of the Column. Something like:

    var commentWidgets = List();
    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: [
    
              // 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,),
            ],
          ),
        ),
    

    If you don't have the comments data already and need to fetch it, use a FutureBuilder to build the UI once the future completes.

提交回复
热议问题