Flutter 将所有小部件中的内容堆叠起来?
我有这样一个小部件树:Flutter 将所有小部件中的内容堆叠起来?,flutter,widget,flutter-layout,flutter-widget,stacklayout,Flutter,Widget,Flutter Layout,Flutter Widget,Stacklayout,我有这样一个小部件树: Stack( children: [ Text( '-', style: title, ), Positioned.fill( child: Center( child: Text( 'FT', style: normal, ), ), ) ], ),
Stack(
children: [
Text(
'-',
style: title,
),
Positioned.fill(
child: Center(
child: Text(
'FT',
style: normal,
),
),
)
],
),
我希望堆栈将_内容的宽度和高度包装到其中的所有小部件,如下所示:
Stack(
children: [
Text(
'-',
style: title,
),
Positioned.fill(
child: Center(
child: Text(
'FT',
style: normal,
),
),
)
],
),
但是它看起来像这样:
Stack(
children: [
Text(
'-',
style: title,
),
Positioned.fill(
child: Center(
child: Text(
'FT',
style: normal,
),
),
)
],
),
堆栈从unfill小部件获取宽度和高度。
如果我将两个小部件都包装在Positioned.fill中,则布局为空。
有人知道怎么解决这个问题吗?Tk很多。您可以使用
堆栈
小部件的对齐
属性
试试这个
Stack(
alignment: Alignment.center,
children: [
Text(
'GAME',
style: TextStyle(color: Colors.blue),
),
Text(
' - ',
style: TextStyle(color: Colors.red),
),
],
),
输出
根据:
堆栈自身的大小将包含所有未定位的子级
因此,基于这一点,我们需要使用未定位的子对象,尽管它仍然可以与Align
或类似的Center
对齐
堆栈(
儿童:[
居中(
子:文本(
' - ',
),
),
居中(
子:文本(
“英尺”,
),
),
],
);