flutter Error the screen overflows horizontally

64 Views Asked by At

I want to scroll the overflowing screen horizontally. I used SingleChildScrollView, but the widget was not visible. I've tried both listview and SingleChildScrollView, but I keep getting a notification that the size of the horizontal axis is the problem. "A RenderFlex overflowed by 163 pixels on the right."

>   if (forChart)
>     Container(
>       child: SingleChildScrollView(
>         scrollDirection: Axis.horizontal,
>         child: Row(
>           children: [
>             Container(
>               width: 160.0,
>               color: Colors.yellow,),
>             Container(
>               width: 160.0,
>               color: Colors.yellow,),
>             Container(
>               width: 160.0,
>               color: Colors.yellow,),
>           ],
>         ),
>       ),
>     )

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER
>   if (forChart)
>     Container(
        height: 200,
        width:double.maxFinite
>       child: SingleChildScrollView(
>         scrollDirection: Axis.horizontal,
>         child: Row(
>           children: [
>             Container(
>               width: 160.0,
>               color: Colors.yellow,),
>             Container(
>               width: 160.0,
>               color: Colors.yellow,),
>             Container(
>               width: 160.0,
>               color: Colors.yellow,),
>           ],
>         ),
>       ),
>     )

Wrap your container to Expanded widget if you are using column widget as parent or else provide height and width to container.