Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Prevent Margin Clipping

I have a horizontal ListView.builder. The image attached demonstrates my UI.

The listView (red). itemBuilder button widgets (blue); The margin (green).

enter image description here

When the list is scrolled to the edge, without a margin, my button will be visibly against the edge of the screen.

If I add a margin or padding via a Container or the ListView, it moves my UI in as expected.

However, when I scroll my list, items in the list are now clipped by this margin and do not scroll to the edge of the screen, but the margin boundary.

How can I have an inset that doesn't clip my list when scrolling?

like image 404
Josh Kahane Avatar asked Jun 22 '18 15:06

Josh Kahane


People also ask

How do you stop a column from overflowing flutter?

The solution to resolve this overflow error is to make your entire widget or in our case the Column scrollable. We can do that by wrapping our Column inside a SingleChildScrollView.

What is clipBehavior in flutter?

Clip clipBehavior. Controls how the contents of the dialog are clipped (or not) to the given shape. See the enum Clip for details of all possible options and their common use cases. Defaults to Clip. none, and must not be null.

How do you handle overflow in flutters?

The Text may overflow from the widgets like containers, cards, etc. The Text Widget has a property overflow to handle the overflow text in android, IOS, WEB, desktop applications. Overflow property has multiple parameters like clip, ellipsis, fade, visible, etc.


1 Answers

ListView possess a padding property for that purpose.

The following code will offset the first element by 8. But that padding won't clip the list content, as opposed to wrapping ListView inside a Padding.

   ListView.builder(
      padding: EdgeInsets.only(top: 8.0),
      itemBuilder: (context, index) {
        return Container(
          height: 42.0,
          color: index % 2 == 0 ? Colors.red : Colors.blue,
        );
      },
    ),
like image 165
Rémi Rousselet Avatar answered Sep 17 '22 19:09

Rémi Rousselet