Flutter: Minimum height on horizontal list view

后端 未结 7 1080
鱼传尺愫
鱼传尺愫 2020-12-02 08:54

I\'m trying to create a horizontal scrolling list of items in Flutter, and I want that list to only take up the necessary height based on its children. By design “List

相关标签:
7条回答
  • 2020-12-02 09:25

    By applying all the above solution there is no suitable answer found yet, which help us to set horizontal Listview If we don't know the height. we must have to set height in all the cases. so I applied the below solution which works for me without specifying any height for the list items. which @sindrenm has already mentioned in his question. so I would like to go with it till a feasible solution will found. I applied shrinkWrap: true but it will shrink the ListView along the main-axis. (only for vertical scrollView) and Not along the cross-axis as asked in the question. so in the nearest future, anyone can go with this solution in the production as well, it works great for me for my all horizontal lists.

    //below declared somewhere in a class above any method and assume list has filled from some API.
    var mylist = List<myModel>();
    
    
    SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              children: [
                    for (int index = 0; index < mylist.length; index++) 
                          listItem(mylist[index]);
             ],
            ),
          ),
        ),
    
        listItem(){
          return Column(
             children[
                widget1(),
                widget2().... etc..
          ]);
        }
    
    0 讨论(0)
提交回复
热议问题