由于溢位,我試圖將我的列小部件包裝在單個子滾動視圖中。但是當我試圖包裝它時,我收到了諸如
RenderFlex 子項具有非零 flex,但傳入的高度約束是無界的。
RenderBox 沒有布局:RenderFlex#dc736relayoutBoundary=up12 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart':失敗的斷言:line 1930 pos 12:'hasSize'
我該怎么做才能防止應用程式中的像素溢位?這是我的代碼:
return Scaffold(
appBar: AppBar(
title: Text('Edit your pet`s details'),
backgroundColor: Color.fromRGBO(101, 69, 112, 1.0),
),
body: Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget> [
Row(
children: <Widget>[
Expanded(
child: TextFieldWidget(
controller: _petNameController,
helperText: "Pet's Name",
)),
],
),
Padding(
padding: const EdgeInsets.only(left: 50.0, right: 50.0),
child: Divider(
color: Colors.grey,
thickness: 0.5,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 60.0,),
Text(
"$_petName is a $_petGender. Update gender",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w400,
),
)
],
),
Expanded(
child: GridView.count(
crossAxisCount: 2,
primary: false,
scrollDirection: Axis.vertical,
children: List.generate(petGenders.length, (index) {
return GestureDetector(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
color:
selectedIndex == index ? primaryColor : null,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
petGenders[petKeys[index]],
SizedBox(
height: 15.0,
),
Text(
petKeys[index],
style: TextStyle(
color: selectedIndex == index
? Colors.white
: null,
fontSize: 18.0,
fontWeight: FontWeight.w600),
),
],
),
),
),
onTap: () {
setState(() {
widget.pet.gender = petKeys[index];
selectedIndex = index;
});
});
}),
),
),
uj5u.com熱心網友回復:
錯誤來自這樣Column一個事實,即您包含一個Extended小部件,該小部件強制使用最大垂直空間。在SingleScrollChildView沒有限制的垂直空間可以使用。
結果是您有一個小部件試圖占據無限的垂直空間。
你怎么能解決這個問題?要么洗掉Extended小部件,要么洗掉小SingleScrollChildView部件。或者,您也可以Extended使用另一個具有定義大小或約束的小部件包裝您的小部件,例如Container具有屬性height和width.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/385785.html
上一篇:Kotlin-如何回傳嵌套變數?
