我正在使用堆栈小部件在屏幕内显示动画。我只使用了 70% 的屏幕,其余部分我没有使用。我想在那里展示其他东西。当我将堆栈小部件包装在列中时,出现错误:底部被无限像素溢出。
我尝试使用 Container 和 SizedBox 添加自定义高度。还尝试使用 SingleChildScrollView
。还是同样的错误。
代码:
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: whiteColor,
body: Column(
children: [
Stack(
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).size.height * 0.72,
child: FlareActor(
'assets/videos/stars.flr',
alignment: Alignment.center,
fit: BoxFit.cover,
animation: 'Blink',
controller: _controller,
),
),
Container(
child: Transform.scale(
scale: 0.6,
child: FlareActor(
'assets/videos/talking-earth.flr',
alignment: Alignment.center,
fit: BoxFit.cover,
animation: 'activated',
controller: _controller,
),
),
),
Positioned(
left: MediaQuery.of(context).size.width / 3.8,
top: MediaQuery.of(context).size.width / 10,
child: Text(
"Published",
style: GoogleFonts.ptSansNarrow(
color: whiteColor,
fontSize: ScreenUtil().setSp(50),
fontWeight: FontWeight.bold),
),
),
],
),
Text("Test"),
],
),
);
}
}
最佳答案
您需要首先用容器包裹堆栈,设置预定义的高度。这是因为堆栈大小依赖于其父级。
这是 Stack 的官方文档:https://api.flutter.dev/flutter/widgets/Stack-class.html
关于flutter - 通过在列内使用堆栈,底部被无限像素溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64388146/