Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Fixed button next to horizontal scroll

I have a dialog with a button and I want to add a horizontal scroll next to the button, so this way the button is fixed in the left and the scroll is in the right. I tried using a Row but I got the following error:

The following assertion was thrown during performResize(): Horizontal viewport was given unbounded width. . . . The following assertion was thrown during performLayout(): RenderBox was not laid out: RenderViewport#48cb5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1982 pos 12: 'hasSize' . . .

The specific code I used for this is the following:

      SizedBox(
              height: 80,
              child: Row(
                children: <Widget>[
                  AddUsersButton(newTaskCubit: newTaskCubit),
                  SizedBox(
                    height: 80,
                    child: ListView(
                      scrollDirection: Axis.horizontal,
                      children: <Widget>[
                        UserExample(newTaskCubit: newTaskCubit),
                        UserExample(newTaskCubit: newTaskCubit),
                        UserExample(newTaskCubit: newTaskCubit),
                        UserExample(newTaskCubit: newTaskCubit),
                      ],
                    ),
                  )
                ],
              ),
            ),
like image 690
Gustavo F. Avatar asked Feb 14 '26 20:02

Gustavo F.


2 Answers

Give SizeBox() width also and use shrikWrap with your Listview .As the scroll is Horizontal its asking for you a fixed widht.

like image 144
Saddan Avatar answered Feb 16 '26 23:02

Saddan


You can use shrinkWrap: true, on ListView

SizedBox(
  height: 80,
  child: ListView(
    shrinkWrap: true,
    scrollDirection: Axis.horizontal,
    children: <Widget>[....],
  ),

You can check more about What does the shrinkWrap property do in Flutter?

like image 43
Yeasin Sheikh Avatar answered Feb 16 '26 23:02

Yeasin Sheikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!