【问题标题】:Why can't I scroll page?为什么我不能滚动页面?
【发布时间】:2021-01-24 08:29:20
【问题描述】:

我有一个小部件 ListView,但我仍然无法滚动图片。我尝试更换 Column 但它仍然对我不起作用。还有其他选择吗?

另外,当我用 SingleChildScrollView 包装 StreamBuilder 时,我收到以下错误:

RenderBox 未布局:RenderRepaintBoundary#9fda5 relayoutBoundary=up11 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': 断言失败:第 1702 行第 12 行:'hasSize'

这是我的代码:

StreamBuilder(
          stream: Firestore.instance
              .collection('userImage')
              //  .orderBy('date', descending: true)
              .where('name', isEqualTo: name)
              .snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData)
              return Center(child: CircularProgressIndicator());
            return ListView(
              children: [
                Row(
                  children: [
                    Text('$name'),
                    IconButton(
                        icon: Icon(
                          Icons.open_in_new,
                          size: 30,
                          color: Colors.grey,
                        ),
                        onPressed: logout)
                  ],
                ),
                Row(
                  children: [
                    Image.asset(
                      'assets/like.png',
                      height: 30,
                      width: 30,
                    ),
                    Image.asset(
                      'assets/donate.png',
                      height: 30,
                      width: 30,
                    ),
                    Icon(
                      Icons.offline_bolt,
                      color: Colors.grey,
                      size: 36,
                    ),
                  ],
                ),
                Padding(
                  padding: const EdgeInsets.only(
                      left: 100, right: 100, top: 50, bottom: 50),
                  child: RaisedButton(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(15)),
                    child: SizedBox(
                      height: 50,
                      child: Center(
                          child: Text(
                        'order pics & clips',
                        style: TextStyle(color: Colors.white),
                      )),
                    ),
                    onPressed: () {
                      print(name);
                      print(email);
                      print(account);
                    },
                  ),
                ),
                ListView.builder(
                    scrollDirection: Axis.vertical,
                    shrinkWrap: true,
                    itemCount: snapshot.data.documents.length,
                    itemBuilder: (context, i) {
                      return Column(
                        children: [
                          ProfilePost(
                              snapshot.data.documents[i]['url'],
                              snapshot.data.documents[i]['likes'].toString(),
                              snapshot.data.documents[i]['donations']
                                  .toString())
                        ],
                      );
                    }),
              ],
            );
          }),

【问题讨论】:

  • 你说的是listview还是listview.builder?你有两个列表
  • 我建议您将 List 包装为 Container 或 SizedBox 并给它一个高度然后检查?

标签: flutter dart


【解决方案1】:

您可以在ListView()ListView.builder() 小部件上使用shrinkWrap: true 属性,以便列表视图的总大小(高度)是子项高度的总和。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多