mcfred
mcfred

Reputation: 1401

A RenderFlex overflowed by 1.00 pixels on the bottom. The relevant error-causing widget was Column

I have a screen which contains a togglebutton widget followed by a card widget which contains a form, followed by another card widget. I searched about this error and the suggested fix is to add an expanded widget. However, I am a noob and I don't know where to add the Expanded widget. Will appreciate your help.

Widget build(BuildContext context) {
    final cart = Provider.of<Cart>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('Your Cart'),
      ),
      body: Container(
        child: 
        Column
      (
      // child: Expanded(

       // child:Column(
         
        children: <Widget>[
            
            SizedBox(height: 10),
           if(cart.totalAmount > 0)ToggleButtons(
                borderColor: Colors.black26,
                fillColor: Theme.of(context).primaryColor,
                borderWidth: 2,
                selectedBorderColor: Colors.black,
                selectedColor: Colors.white,
                borderRadius: BorderRadius.circular(40),
                children: <Widget>[
                    Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                        'I will pickup',
                        style: TextStyle(fontSize: 16),
                    ),
                    ),
                    Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                        'Please deliver',
                        style: TextStyle(fontSize: 16),
                    ),
                    ),
                ],
                onPressed: (int index) {
                 //   print('index ' + index.toString()); 
                    setState(() {
                     // print('Inside state changed'); 
                    for (int i = 0; i < _isSelected.length; i++) {
                        print(_isSelected[i] = i == index); 
                        _isSelected[i] = i == index; 
                    }
                    });
                },
                isSelected: _isSelected,
                ),

          SizedBox(height: 10),
          if(_isSelected[1]) AddressScreen(),
           SizedBox(height: 10),
          Expanded(
            child: ListView.builder(
              itemCount: cart.items.length,
              itemBuilder: (ctx, i) => CartItem(
                    cart.items.values.toList()[i].id,
                    cart.items.keys.toList()[i],//returns productId 
                    cart.items.values.toList()[i].price,
                    cart.items.values.toList()[i].quantity,
                    cart.items.values.toList()[i].title,
                  ),
            ),
          ),
          Card(
            margin: EdgeInsets.all(15),
            child: Padding(
              padding: EdgeInsets.all(8),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    'Total',
                    style: TextStyle(fontSize: 20),
                  ),
                  Spacer(),
                  Chip(
                    label: Text(
                      '\Tsh. ${cart.totalAmount.toStringAsFixed(2)}',
                      style: TextStyle(
                        color: Theme.of(context).primaryTextTheme.title.color,
                      ),
                    ),
                    backgroundColor: Theme.of(context).primaryColor,
                  ),
           OrderButton(cart: cart)
                ],
              ),
            ),
          ), 
        ],
      ),
      )
     //   ),
    //  ),
    );
  }
}

Error message:

A RenderFlex overflowed by 1.00 pixels on the bottom.

The relevant error-causing widget was Column lib\screens\cart_screen.dart:40 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#d61dc relayoutBoundary=up1 OVERFLOWING ════════════════════════════════════════════════════════════════════════════════

Upvotes: 0

Views: 2207

Answers (1)

DK_bhai
DK_bhai

Reputation: 359

Wrap your column in SingleChildScrollView( child: Column(.....))
you can remove the container as well in body if not using any of its properties and directly say body: SingleChildScrollView(...)

Upvotes: 1

Related Questions