這是我的代碼.. 我收到錯誤訊息,說“BoxConstraints 強制無限高度”。然后是描述,我是新手,我沒有辦法解決這個問題。
body:SingleChildScrollView(
child: Stack(
fit: StackFit.expand,
children: [
Image(
color: Colors.black12,
colorBlendMode: BlendMode.darken,
image: AssetImage('images/Alone.jpg'),
fit: BoxFit.cover,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Show('Alone is Stronger', 'y'),
],
)
],
),
),
這是我的 Show 小部件。
Widget Show(String x,String y){
return
Container(
margin: EdgeInsets.fromLTRB(10, 5, 10, 2),
width: 400,
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.all(10),
child: Text(
'$x',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.yellowAccent,
),
),
);
}
很多問題已經在這里遇到了同樣的問題,但我不明白問題出在哪里。提前致謝
uj5u.com熱心網友回復:
從您的代碼片段中,我可以理解您正在嘗試了解body.
SingleChildScrollView提供無限高度,雖然Stack是它的孩子并使用父尺寸,它將獲得無限高度并通過錯誤。
在您的情況下,小部件結構將是
body: Stack(
fit: StackFit.expand,
children: [
Image(
color: Colors.black12,
colorBlendMode: BlendMode.darken,
image: AssetImage('images/Alone.jpg'),
fit: BoxFit.cover,
),
SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Show('Alone is Stronger', 'y'),
],
))
],
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/366993.html
上一篇:Flutter函式重新加載變數
