[英]Position a widget, inside a stack, but according to the center of the widget
我想 position 一个小部件CustomWidget
,但在指定的 position,即顶部,左侧值,在Positioned
小部件中,我希望有我的CustomWidget
的中心,而不是我的CustomWidget
的左上角。
我想要这样的东西:-
Stack(
children: [
Positioned(
left: x,
top: y,
alignment: Alignment.center, //Alignment of the child widget, such that at (x, y) there is the center of the widget.
child: CustomWidget(),
),
],
);
这是我正在尝试制作的 UI 类型,我正在尝试制作两种情况:-
CustomWidget
没有任何特定类型,我目前正在尝试制作一个通用方法,它可能是具有一些变量值的简单Text
Widget,或者可能是具有Image
、 Divider
和Text
Row
的 Widget。 我基本上将CustomWidget
用作一种弹出窗口,将在一些额外信息的情况下使用,也用作小部件上的标记,无论用户单击何处,在这两种情况下,我都无法确定大小。
注意:- 我确实希望 position CustomWidget
在堆栈中的指定偏移量处,但希望应该有 CustomWidget 的中心而不是CustomWidget
的CustomWidget
。
您不需要使用Positioned
小部件。 尝试使用Align
小部件,记得添加alignment: Alignment.center,
使其居中。
我开发了一个package ,其中包含许多有用的组件(基本上是我在所有项目中经常使用的组件,以防止到处写相同的东西)。 所以我根据上面的问题添加了这个名为PositionedAlign的新Widget
。 我希望这可以帮助任何可能需要它的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.