flutter 我无法在SinglechildScrollview中使用列表视图.生成器

5fjcxozz  于 2023-02-25  发布在  Flutter
关注(0)|答案(2)|浏览(124)
body: (
          SafeArea(
           child: SingleChildScrollView(
             child: Column(
               children: [
                 ListView.builder(
                   itemBuilder: (context,index)
                   {
                     return(
                         Container(
                           height: 100,
                           width: 100,
                           color: Colors.red,
                         )
                     );
                   },
                   itemCount: 20,
                 ),
               ],
             )
           ),
          )
      ),

我想让它的滚动列表的项目基本上试图复制用户界面的instagram

emeijp43

emeijp431#

既然ListView.builder已经包含了滚动功能,您不需要使用SingleChildScrollView,那么您对同时使用它们有什么特殊要求吗?如果有,您可以尝试将ListView Package 成SizedBox,并指定一个固定的高度。

qvtsj1bj

qvtsj1bj2#

试试这个:

body: SafeArea(
  child: ListView.builder(
    physics: const AlwaysScrollableScrollPhysics(),
    shrinkWrap: true,
    itemBuilder: (context, index) {
      return Container(
        padding: const EdgeInsets.only(bottom: 10),
        height: 100,
        width: 100,
        color: Colors.red,
      );
    },
    itemCount: 20,
  ),
),

相关问题