Equivalent of RelativeLayout in Flutter

前端 未结 4 1938
后悔当初
后悔当初 2021-01-29 18:00

Is there a way to implement something similar to what RelativeLayout does on Android?

In particular I\'m looking for something similar to centerInPare

4条回答
  •  误落风尘
    2021-01-29 18:19

    Similar to Android's RelativeLayout (and in fact more powerful) is the AlignPositioned widget from the align_positioned package:

    https://pub.dev/packages/align_positioned

    From its docs:

    When your desired layout feels too complex for Columns and Rows, AlignPositioned is a real life saver. Flutter is very composable, which is good, but sometimes it's unnecessarily complex to translate some layout requirement into a composition of simpler widgets.

    The AlignPositioned aligns, positions, sizes, rotates and transforms its child in relation to both the container and the child itself. In other words, it lets you easily and directly define where and how a widget should appear in relation to another.

    For example, you can tell it to position the top-left of its child at 15 pixels to the left of the top-left corner of the container, plus move it two thirds of the child's height to the bottom plus 10 pixels, and then rotate 15 degrees. Do you even know how to start doing this by composing basic Flutter widgets? Maybe, but with AlignPositioned it's much easier, and it takes a single widget.

    However, the specific example in the question is quite simple, I'd just use Rows, Columns etc anyway. Note: I am the author of this package.

提交回复
热议问题