0

Is it possible to allow overflow within a container WITHOUT making that content scrollable? For example:

Container(
  height: 100,
  width: MediaQuery.of(context).size.width,
  child: Row(
    children: List.generate(10, (i) => Container(height: 100.0, width: 300).toList();
   ),
)

I know that it will theoretically work correctly in release, but I'm looking to suppress the overflow warnings while debugging.

I've tried wrapping the Container() in OverflowBox(), but it still shows the overflow warning. Everything else I've tried makes the list scrollable - it needs to stay fixed.

1
  • Use listviewbuilder widget Commented Apr 26, 2021 at 15:10

2 Answers 2

1

To make the List NOT scrollable, use NeverScrollableScrollPhysics() in ListView.
For example

ListView.builder(
          physics: NeverScrollableScrollPhysics(),
          scrollDirection: Axis.horizontal,
          itemCount: 100,
          itemBuilder: (context, i) {
            return Container(
              height: 100.0,
              width: 300,
              margin: EdgeInsets.all(8),
              color: Colors.green,
            );
          },
        ),
Sign up to request clarification or add additional context in comments.

Comments

1

Use SingleChildScrollView whith scrollDirection set to Axis.horizontal, Although it works I recommend ListViewBuilder

Container(
          height: 100,
          width: MediaQuery.of(context).size.width,
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: List.generate(
                10,
                (i) => Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                ),
              ).toList(),
            ),
          ),
        ),

using ListviewBuilder

ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: 100,
              itemBuilder: (context, i) {
                return Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                );
              },
            )

EDIT: Wrap widget will do the trick.

SizedBox(
        height: 100,
        width: MediaQuery.of(context).size.width,
        child: Wrap(
          clipBehavior: Clip.hardEdge,
          direction: Axis.horizontal,
          children: List.generate(
            10,
            (i) => Container(
              height: 100.0,
              width: 300,
              margin: EdgeInsets.all(8),
              color: Colors.green,
            ),
          ).toList(),
        ),
      ),

1 Comment

Thanks for your answer - though I need the content to NOT be scrollable. I'm wondering if that is possible with flutter (without the SDK complaining)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.