简体   繁体   中英

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),
                      ],
                    ),
                  )
                ],
              ),
            ),

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM