flutter icon indicating copy to clipboard operation
flutter copied to clipboard

Extend WrapAlignment with an option to apply space between in combination with center for orphans

Open timovandeput opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

Use case

I have not found any way to automatically align a list of widgets across (potentially) multiple lines using their intrinsic widths, but wrapping orphan widget to the center instead of the start of the next line.

This seems a common use case for footers, where on mobile devices it feels more natural to wrap these orphans to the center instead of the start of the next line.

Proposal

Possible directions could be to either (1) add a new WrapAlignment enum that performs this alignment for orphaned objects, or (2) to support e.g. Spacer widgets that explicitly push objects apart on a line but are ignored at the start/end of a line.

timovandeput avatar May 31 '23 07:05 timovandeput

Hi @timovandeput. Thanks for filing this. Please can you provide minimal complete reproducible code sample to your current implementation and possibly highlight where your proposals fit into?

dam-ease avatar May 31 '23 12:05 dam-ease

(This issue was raised as a "Feature request", so providing a working example is kind-of difficult.)

But to explain a bit in more detail what I would like to achieve:

I want to wrap widgets in a layout such that it applies spaceBetween if multiple widgets fit on the main axis, but center any orphan widgets.

E.g.:

If there is sufficient space, the layout is like alignment: WrapAlignment.spaceBetween:

|A--BB--CCCC|

But if the space is constrained it should wrap the orphaned widget to the center of the next line (instead of the start of the line) like alignment: WrapAlignment.center would:

|A-----BB|
|--CCCC--|

And if there is even less room, all widgets wrap as orphans:

|-A--|
|-BB-|
|CCCC|

I would like to achieve this for widgets that impose their preferred size (like text widgets of an unpredictable width).

timovandeput avatar May 31 '23 12:05 timovandeput