我有一个容器与线性渐变的目的,作为我的应用程序的背景颜色。当我把一列作为子元素时,我的背景只在列大小上起作用。剩余的空格是一个空格。
我试过将脚手架的背景颜色设置为透明,但它变成了黑色空间而不是空白空间
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Container(
padding: EdgeInsets.all(32),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.1, 0.9],
colors: [
HexColor("#2a4644"),
HexColor("#3c1630"),
],
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('test')
],
)
),
);
}
}
这是它现在的屏幕截图:http://prntscr.com/o64s1f
发布于 2019-06-25 04:58:27
你必须使用一个堆栈。Container应该占据整个屏幕的宽度和高度。然后将该列放在Container前面。
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.1, 0.9],
colors: [
Color(0xFF2a4644),
Color(0xFF3c1630),
],
),
),
),
Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('test')
],
),
),
],
),
);
}
https://stackoverflow.com/questions/56743766
复制相似问题