我正在嘗試將 a 添加boxShadow到 aContainer但它BoxShadow正在整個螢屏寬度上而不是Sized Box. 進一步解釋Containeris a child并且SizedBoxis SizedBoxin Columnthe is crossAxisAlignment。代碼如下。Columnstretch
class _AudioDetailsState extends State<AudioDetails> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(heading: "Audio Player"),
body: SafeArea(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.blue.shade50],
begin: Alignment.topCenter,
end: Alignment.bottomCenter),
),
padding: const EdgeInsets.all(10),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ClipOval(
child: SizedBox(
height: 150,
width: 150,
child: Container(
height: 125,
width: 125,
decoration: BoxDecoration(boxShadow: [
BoxShadow(
blurRadius: 5,
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
)
]),
child: const CircleAvatar(
backgroundColor: Colors.amber,
)),
),
)
],
)),
),
);
}
}
輸出的當前影像如下

uj5u.com熱心網友回復:
這是因為crossAxisAlignment值的原因,使用CrossAxisAlignment.stretch將在交叉軸上拉伸子級。
檔案說“如果孩子想要與其父母不同的大小,而父母沒有足夠的資訊來對齊它,那么孩子的大小可能會被忽略。在定義對齊時要具體。”
要解決此問題,您可以使用其他crossAxisAlignment值并將設備寬度提供給父級Container
Container(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ClipOval(
...
或者用Align
Align(
child: ClipOval(
child: SizedBox(
height: 150,
width: 150,
child: Container(
height: 125,
width: 125,
decoration: BoxDecoration(boxShadow: [
BoxShadow(
blurRadius: 5,
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
)
]),
child: const CircleAvatar(
backgroundColor: Colors.amber,
),
),
),
),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/449676.html
上一篇:我如何讀取xml檔案值
