【问题标题】:How to display listview inside a Column?如何在列内显示列表视图?
【发布时间】:2020-12-30 05:25:21
【问题描述】:

在我的 App 个人资料页面中有 3 个容器。第一个容器显示个人资料图片和名称。 第二个容器有一个带有 3 个值(帖子、类别和个人资料)的下拉按钮。 第三个容器有一个列作为一个孩子。我想为帖子和类别使用列表视图构建器的这个专栏和个人资料已准备好并完美显示。我在列子项中使用了以下代码

Container(
  padding: EdgeInsets.only(top: 10.0),
  width: double.infinity,
  child: Column(
    mainAxisAlignment: MainAxisAlignment.start,
    children: [
       _selectedItem == "posts" ?
       "I want to use listview builder here" 
       :
       Container(
         height: 0.0,
         child: Text(""),
       ),
       _selectedItem == "categories" ?
       "I want to use listview builder here" 
       :
       Container(
         height: 0.0,
         child: Text(""),
       ),
       _selectedItem == "profile" ?
       "this is working fine and able to see output" 
       :
       Container(
         height: 0.0,
         child: Text(""),
       ),
   ],
  ),
),

我什至在 stackoverflow 上搜索了很多示例,但找不到任何适合我需要的示例。配置文件信息、帖子和类别从服务器获取并存储在 var userProfile 中;列出 userPosts = new List();列出 postCategories = new List();分别。我尝试了很多例子来满足我的需要,虽然不是按照我的要求而是给出了错误。

如果有人能给我解决方案,我将不胜感激。 提前致谢

【问题讨论】:

    标签: flutter-listview


    【解决方案1】:

    无论您想在哪里添加列表,只需将这段代码粘贴到那里,它就可以正常工作。

        ListView.builder(
           shrinkWrap: true,
           //If you get infinite height error use this attribute, it will shrink height of the list to display only available items.
           physics: NeverScrollableScrollPhysics(),
           //if you want to disable scrolling
           itemBuilder: (context, index) {
                  return Text(NamesList[index].name); //Here NamesList is your data list
                 },
               )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多