我想将小部件放置在Stack的顶部中心,但是它正像下面的屏幕截图一样被拉伸到父级的宽度:
这是我正在使用的代码:
@override
Widget build(BuildContext context) {
return Scaffold(
key: key,
appBar: AppBar(
title: Text("Just a test app"),
),
body: Stack(
children: <Widget>[
Positioned(
left: 0,
right: 0,
child: Card(
child: Text("A variable sized text"),
),
),
],
),
);
}
答案 0 :(得分:1)
将您的Card
换成Align
或Center
:
Stack(
children: <Widget>[
Positioned(
top: 50,
left: 0,
right: 0,
child: Center(
child: Card(
child: Text("A variable sized text"),
),
),
),
Align(
alignment: Alignment.topCenter, //that also works
child: Card(
child: Text("Another variable sized text"),
),
)
],
),