【问题标题】:I can't use Listview.builder inside SinglechildScrollview我不能在 SinglechildScrollview 中使用 Listview.builder
【发布时间】:2023-02-25 02:34:46
【问题描述】:
body: (
          SafeArea(
           child: SingleChildScrollView(
             child: Column(
               children: [
                 ListView.builder(
                   itemBuilder: (context,index)
                   {
                     return(
                         Container(
                           height: 100,
                           width: 100,
                           color: Colors.red,
                         )
                     );
                   },
                   itemCount: 20,
                 ),
               ],
             )
           ),
          )
      ),

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

【问题讨论】:

    标签: flutter listview builder singlechildscrollview


    【解决方案1】:

    由于ListView.builder 已经包含滚动功能,因此您不需要使用SingleChildScrollView,您对同时使用它们有什么具体要求吗?如果是这样,您可以尝试将 ListView 包装成 SizedBox 并指定固定高度。

    【讨论】:

      【解决方案2】:

      尝试这个:

      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,
        ),
      ),
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-05
        • 2020-07-09
        • 2021-10-06
        • 2020-03-22
        • 1970-01-01
        • 2021-11-11
        • 2021-10-07
        • 2020-09-04
        相关资源
        最近更新 更多