首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需求.布局需求.油漆需求.合成.比特.更新

需求.布局需求.油漆需求.合成.比特.更新
EN

Stack Overflow用户
提问于 2020-04-30 04:36:12
回答 1查看 5.1K关注 0票数 1

我尝试在ListView中运行包含Gridview的代码

代码语言:javascript
复制
      body: ListView(
        shrinkWrap: true,
        children: <Widget>[
          Stack(
            children: <Widget>[
              Container(
                alignment: Alignment(0.0, -0.40),
                height: 100.0,
                color: Colors.white,
                child: Text(
                  'أحصل على تدريب',
                  style: TextStyle(fontFamily: 'Janna', fontSize: 20.0),
                ),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(25.0, 90.0, 25.0, 0.0),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(20.0),
                    boxShadow: [
                      BoxShadow(
                        blurRadius: 2.0,
                        color: Colors.grey,
                      )
                    ]),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Stack(
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.fromLTRB(25.0, 25.0, 35.0, 25.0),
                          child: Text(
                            'لديك',
                            style: TextStyle(
                                fontFamily: 'Janna',
                                color: Colors.grey,
                                fontWeight: FontWeight.bold,
                                fontSize: 16.0),
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.fromLTRB(25.0, 50.0, 25.0, 25.0),
                          child: Text(
                            '200',
                            style: TextStyle(
                                fontFamily: 'Janna',
                                color: Colors.black,
                                fontWeight: FontWeight.bold,
                                fontSize: 30.0),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      width: 100,
                    ),
                    Container(
                      height: 50,
                      width: 120,
                      decoration: BoxDecoration(
                        color: Colors.greenAccent[100].withOpacity(0.7),
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                      child: Center(
                        child: Text(
                          'إشتري المزيد',
                          style: TextStyle(
                              fontFamily: 'Janna',
                              color: Colors.green,
                              fontWeight: FontWeight.bold,
                              fontSize: 15.0),
                        ),
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
          SizedBox(
            height: 40.0,
          ),
          Container(
            padding: EdgeInsets.only(left: 25.0, right: 25.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  'المدربين',
                  style: TextStyle(
                      fontFamily: 'Janna',
                      color: Colors.grey,
                      fontWeight: FontWeight.bold,
                      fontSize: 14.0),
                ),
                Text(
                  'أظهر الجلسات السابقة',
                  style: TextStyle(
                      fontFamily: 'Janna',
                      color: Colors.green,
                      fontWeight: FontWeight.bold,
                      fontSize: 14.0),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 20.0,
          ),
          GridView.count(
            shrinkWrap: true,
            physics: ClampingScrollPhysics(),
            crossAxisCount: 2, // Number of Cards in each Row
            primary: false,
            crossAxisSpacing: 4.0, // Space between Cards
            mainAxisSpacing: 4.0, // Space between Rows

            children: <Widget>[
              _buildCard('فدوى', 'متوفر', 1,
                  'https://i.pinimg.com/originals/64/ce/92/64ce9246abec3f86b7d5a8d2a562a03c.jpg'),
              _buildCard('فدوى', 'متوفر', 2,
                  'https://i.pinimg.com/originals/64/ce/92/64ce9246abec3f86b7d5a8d2a562a03c.jpg'),
              _buildCard('فدوى', 'متوفر', 3,
                  'https://i.pinimg.com/originals/64/ce/92/64ce9246abec3f86b7d5a8d2a562a03c.jpg'),
              _buildCard('فدوى', 'متوفر', 4,
                  'https://i.pinimg.com/originals/64/ce/92/64ce9246abec3f86b7d5a8d2a562a03c.jpg'),
              _buildCard('فدوى', 'متوفر', 5,
                  'https://i.pinimg.com/originals/64/ce/92/64ce9246abec3f86b7d5a8d2a562a03c.jpg'),
              _buildCard('فدوى', 'متوفر', 6,
                  'https://i.pinimg.com/originals/64/ce/92/64ce9246abec3f86b7d5a8d2a562a03c.jpg'),
            ],
          )
        ],
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Widget _buildCard(String name, String status, int cardIndex, String img) {
    return Card(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      elevation: 7.0,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          SizedBox(
            height: 12.0,
          ),
          Container(
            child: Column(
              children: <Widget>[
                Stack(
                  children: <Widget>[
                    CircleAvatar(
                      radius: 35.0,
                      backgroundImage: NetworkImage(img),
                    ),
                    Container(
//                      padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      child: CircleAvatar(
                        radius: 10.0,
                        backgroundColor: Colors.white,
                        child: CircleAvatar(
                          radius: 6.0,
                          backgroundColor:
                              status == 'بعيد' ? Colors.grey : Colors.green,
                        ),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: 8.0,
                ),
                Text(
                  status,
                  style: TextStyle(
                      fontFamily: 'Janna',
                      fontSize: 14.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.grey),
                ),
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.all(7.0),
            width: double.infinity,
            decoration: BoxDecoration(
              color: status == 'بعيد' ? Colors.grey : Colors.green,
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(10.0),
                bottomRight: Radius.circular(10.0),
              ),
            ),
            child: Center(
              child: Text(
                'طلب',
                style: TextStyle(
                  fontSize: 20.0,
                  fontFamily: 'Janna',
                  fontWeight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
            ),
          )
        ],
      ),
      margin: cardIndex.isEven
          ? EdgeInsets.fromLTRB(25.0, 0.0, 5.0, 10.0)
          : EdgeInsets.fromLTRB(10.0, 0.0, 25.0, 10.0),
    );
  }
}

每次我得到这个错误,不管我改变了什么。

╞═════════════════════════════════════════════════════════i/

( 9523):呈现库performResize I/flutter (9523)捕获的══╡异常:在performResize():I/flutter (9523)期间抛出以下断言:垂直视图被赋予无限高。I/颤振( 9523):视图在滚动方向展开以填充它们的容器。在这种情况下,垂直I/颤振( 9523):viewport被给予无限的垂直空间来扩展。这种情况I/flutter ( 9523):通常发生在可滚动小部件嵌套在另一个可滚动小部件中时。I/flutter ( 9523):如果这个小部件总是嵌套在一个可滚动的小部件中,那么就不需要使用视口了,因为I/flutter ( 9523):将始终有足够的垂直空间供子部件使用。在这种情况下,可以考虑使用列I/颤振( 9523):代替。否则,考虑使用"shrinkWrap“属性(或.

)

EN

回答 1

Stack Overflow用户

发布于 2021-04-14 13:02:16

我也试过你的最小复制,它看起来很好。正如注释中提到的,您可以尝试运行flutter clean然后运行flutter run。此问题可能是由未包含在构建中的代码更改造成的。

如果未定义父部件高度,则通常会导致错误"Vertical viewport was given unbounded height"。这将导致ListView的高度无限,ListView需要定义其高度。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61516004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档