[英]A RenderFlex overflowed by 99888 pixels on the bottom
我在“HomeScreen”上遇到了一些問題,但在不確定發生了什么之前它可以正常工作,現在它不能正常工作。 還有一個疑問,因為我已經添加了一個容器,並且列也在容器內部,為什么列會溢出?
我想在左側和右側有一個用於顯示圖像的“容器”,用於顯示從數據庫中獲取的“UserInformation”,但是它顯示列問題,即使已添加“靈活”或“擴展”也不起作用。
“主屏幕顯示”
@override
Widget build(BuildContext context) {
final profile = Provider.of<UserProfileLogic>(context, listen: false);
return Container(
color: Colors.blue,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.all(40),
child: CircleAvatar(
backgroundImage: AssetImage(
"assets/images/Materials-25.png",
),
radius: 70,
child: FittedBox(
fit: BoxFit.fitHeight,
),
),
),
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: profile.items.length,
itemBuilder: (_, i) => Column(
children: <Widget>[
Text(profile.items[i].username),
Text(profile.items[i].age.toString()),
Text(profile.items[i].gender),
Text(profile.items[i].bio),
SizedBox(
height: 50,
),
UserProfileItem(profile.items[i].userprofileid),
],
),
),
],
),
),
],
),
);
}
}
“UserProfileItem.dart”創建這個的原因是因為我必須傳遞“ID”的參數以確保一旦用戶單擊按鈕,它將獲得 ID,因此一旦進入“ProfileScreen”就可以看到他自己的個人資料。
class UserProfileItem extends StatelessWidget {
final String id;
UserProfileItem(this.id);
@override
Widget build(BuildContext context) {
return RaisedButton(
child: Text("Profile"),
elevation: 6,
onPressed: () => Navigator.of(context).pushNamed(
ProfileScreen.routeName,
arguments: id,
),
);
}
}
“使用后的解決方案”我可以知道為什么它會顯示出來嗎? 謝謝您的幫助
溢出不是問題。 溢出是由 flutter 中的錯誤小部件引起的。
@override
Widget build(BuildContext context) {
final profile = Provider.of<UserProfileLogic>(context, listen: false);
return Container(
color: Colors.blue,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.all(40),
child: CircleAvatar(
backgroundImage: AssetImage(
"assets/images/Materials-25.png",
),
radius: 70,
child: FittedBox(
fit: BoxFit.fitHeight,
),
),
),
Expanded(
child: ListView.builder(
itemCount: profile.items.length,
itemBuilder: (_, i) => Column(
children: <Widget>[
Text(profile?.items[i]?.username ?? "No user name"),
Text(profile?.items[i]?.age?.toString() ?? "No age"),
Text(profile?.items[i]?.gender ?? "No gender"),
Text(profile?.items[i]?.bio ?? "No bio"),
SizedBox(
height: 50,
),
UserProfileItem(profile.items[i].userprofileid),
],
),
),
),
],
),
);
}
}
問題是您的項目字段中有 null 值。 要解決此問題,請如上所述更改您的文本小部件。
問題是您將ListView.builder
作為Column()
的子級,並且 Columns 不會滾動,將該列更改為ListView
並且您的問題將得到解決。
還要檢查您是否嘗試訪問 null 值並為文本小部件提供默認值,文本小部件的數據不能是 null。
Flexible(
child: ListView(
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: profile.items.length,
itemBuilder: (_, i) => Column(
children: <Widget>[
Text(profile?.items[i]?.username ?? "No username"),
Text(profile?.items[i]?.age?.toString() ?? "No age"),
Text(profile?.items[i]?.gender ?? "No gender"),
Text(profile?.items[i]?.bio ?? "No bio"),
SizedBox(
height: 50,
),
UserProfileItem(profile.items[i].userprofileid),
],
),
),
],
),
),
關於您獲得的重復列表,請檢查 profile.items.length 的值,因為您將其用作 itemCount。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.