如何修复颤动中的“底部 283 像素溢出的 RenderFlex”?

时间:2021-06-17 21:24:32

标签: flutter flutter-layout

错误发生在我试图呈现贡献列表的屏幕中。我尝试了很多方法(如下所列),但都没有奏效。

  1. 使用 Expanded() 包装我的列小部件
  2. 使用 Flexible() 包装我的 Column 小部件
  3. 用 SingleScrollView() 包装我的 Listview.builder() 然后在其中添加 physics: NeverScrollableScrollPhysics()enter image description here

我有一个包含 Lisview.builder() 的贡献屏幕

这是我的贡献屏幕

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My Chamas'),
        centerTitle: true,
      ),
      floatingActionButton: CustomFloatingActionButton(
        buttonLabel: 'Contribute +',
      ),
      resizeToAvoidBottomInset: false,
      body: Column(
        children: <Widget>[
          Container(
            height: MediaQuery.of(context).size.height * 0.22,
            margin: EdgeInsets.only(top: 20),
            child: PageView.builder(
              itemCount: widget.availableChamas.length, // number of cards
              controller: PageController(viewportFraction: 0.8),
              onPageChanged: (int index) => setState(() => _index = index),
              /*** Begin snapping chama cards */
              itemBuilder: (_, i) {
                return Transform.scale(
                  scale: i == _index ? 1 : 0.9,
                  child: Card(
                    elevation: 6,
                    margin: EdgeInsets.only(right: 0),
                    color: Theme.of(context).primaryColor, // Card backgound color
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
                    child: Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(25),
                        gradient: LinearGradient(
                          begin: Alignment.topRight,
                          end: Alignment.bottomLeft,
                          stops: [0.1, 0.9],
                          colors: [Colors.indigo, Colors.teal],
                        ),
                      ),
                      child: ChamaCard(
                        id: widget.availableChamas[i].id,
                        name: widget.availableChamas[i].name,
                        totalMembers: widget.availableChamas[i].totalMembers,
                        totalContributions: widget.availableChamas[i].totalContributions,
                      ),
                    ),
                  ),
                );
                /*** End snapping chama cards */
              },
            ),
          ),
          SizedBox(height: 15),
          Container(
            padding: EdgeInsets.only(right: 15, left: 15),
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      'All my chamas',
                      style: TextStyle(fontSize: 15, color: Colors.red[900]),
                    ),
                    Icon(
                      Icons.arrow_forward,
                      size: 17,
                      color: Colors.red[900],
                    )
                  ],
                ),
                SizedBox(height: 15),
                Row(
                  children: <Widget>[
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text('My', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: <Widget>[
                            Text(
                              'Contributions',
                              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
                            ),
                            SizedBox(width: 5),
                            Text(
                              'to this chama',
                              style: TextStyle(color: Colors.green[800]),
                            )
                          ],
                        ),
                      ],
                    )
                  ],
                ),
                SizedBox(height: 10),
                ListView.builder(
                  scrollDirection: Axis.vertical,
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                  itemBuilder: (context, index) {
                    return ChamaListItem(
                      id: widget.availableContributions[index].id,
                      amount: widget.availableContributions[index].amount,
                      contributionDate: widget.availableContributions[index].contributionDate,
                    );
                  },
                  itemCount: widget.availableContributions.length,
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

这是我的 ChamaListItem 小部件,它只包含一张贡献卡。这就是我在 Listview.builder() 中迭代以构建可滚动列表的内容

Widget build(BuildContext context) {
    return Card(
      elevation: 4,
      shadowColor: Color.fromRGBO(255, 255, 255, 0.5),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  'Date',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                SizedBox(height: 5),
                Text(
                  '$contributionDate',
                  style: TextStyle(color: Colors.red[900]),
                )
              ],
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                Text('Kes'),
                SizedBox(width: 1),
                Text(
                  '$amount',
                  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

这是控制台抛出的错误

Performing hot reload...
Syncing files to device sdk gphone x86 arm...
Reloaded 5 of 566 libraries in 1,183ms.

======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 283 pixels on the bottom.

The relevant error-causing widget was: 
  Column file:///Users/Steve/StudioProjects/m_chama/lib/screens/myChamas.dart:35:13
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#3a382 relayoutBoundary=up1 OVERFLOWING
...  needs compositing
...  parentData: offset=Offset(0.0, 105.5); id=_ScaffoldSlot.body (can use size)
...  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=697.5)
...  size: Size(392.7, 697.5)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================

1 个答案:

答案 0 :(得分:0)

Column 包裹 SingleChiledScrollView 小部件