英文:
Another exception was thrown: RenderBox was not laid out: RenderFlex#6ac69
问题
我想要显示一个列表,数据来自API。但是我遇到了错误。
另一个异常被抛出:RenderBox没有布局:RenderPadding#64692 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
我不知道这是什么错误。。
以下是我的问题代码:
return AlertDialog(
insetPadding: EdgeInsets.only(bottom: 520),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
title: Container(
color: Color.fromARGB(255, 253, 253, 253),
child: Text('Comment', style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
padding: const EdgeInsets.all(17),
margin: const EdgeInsets.all(0),
),
titlePadding: const EdgeInsets.all(0),
content: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemCount: commentList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
child: InkWell(
child: Container(
padding: EdgeInsets.only(bottom: 10, top: 10, left: 20, right: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Color(0xffD4D4D4), width: 2.0)),
child: Column(
children: <Widget>[
SizedBox(height: 15),
Expanded(
child: Text(
"test",
textAlign: TextAlign.justify,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal),
))
],
)),
)),
);
},
),
])),
);
希望这可以帮助你解决问题。
英文:
I want to display list and the data come from API. And I got error
Another exception was thrown: RenderBox was not laid out: RenderPadding#64692 relayoutBoundary=up5
NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I don't know what kind of error is this..
Bellow is my issue code
return AlertDialog(
insetPadding: EdgeInsets.only(bottom: 520),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
title: Container(
color: Color.fromARGB(255, 253, 253, 253),
child: Text('Comment', style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
padding: const EdgeInsets.all(17),
margin: const EdgeInsets.all(0),
),
titlePadding: const EdgeInsets.all(0),
content: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: < Widget > [
GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemCount: commentList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
child: InkWell(
child: Container(
padding: EdgeInsets.only(bottom: 10, top: 10, left: 20, right: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Color(0xffD4D4D4), width: 2.0)),
child: Column(
children: < Widget > [
SizedBox(height: 15),
Expanded(
child: Text(
"test",
textAlign: TextAlign.justify,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal),
))
],
)),
)),
);
},
),
])),
);
答案1
得分: 2
SingleChildScrollView
只能包含一个子元素,而 GridView
会扩展以填充可用空间。
为了解决这个问题,您可以将您的 GridView
包装在一个 SizedBox
中,并为其指定一些高度/宽度:
AlertDialog(
insetPadding: EdgeInsets.only(bottom: 520),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
title: Container(
color: Color.fromARGB(255, 253, 253, 253),
child: Text('Comment',
style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
padding: const EdgeInsets.all(17),
margin: const EdgeInsets.all(0),
),
titlePadding: const EdgeInsets.all(0),
content: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
// 在这里添加 SizedBox
SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.5,
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemCount: commentList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
child: InkWell(
child: Container(
padding: EdgeInsets.only(
bottom: 10, top: 10, left: 20, right: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border:
Border.all(color: Color(0xffD4D4D4), width: 2.0)),
child: Column(
children: <Widget>[
SizedBox(height: 15),
Expanded(
child: Text(
"test",
textAlign: TextAlign.justify,
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.normal),
))
],
)),
)),
);
},
),
),
])),
);
英文:
The SingleChildScrollView
can only have one child, and the GridView
expands to fill the available space.
To fix the problem, wrap your GridView
with a SizedBox
and give it some height/width:
AlertDialog(
insetPadding: EdgeInsets.only(bottom: 520),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
title: Container(
color: Color.fromARGB(255, 253, 253, 253),
child: Text('Comment',
style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
padding: const EdgeInsets.all(17),
margin: const EdgeInsets.all(0),
),
titlePadding: const EdgeInsets.all(0),
content: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
// <--- Add SizedBox here
SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.5,
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemCount: commentList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
child: InkWell(
child: Container(
padding: EdgeInsets.only(
bottom: 10, top: 10, left: 20, right: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border:
Border.all(color: Color(0xffD4D4D4), width: 2.0)),
child: Column(
children: <Widget>[
SizedBox(height: 15),
Expanded(
child: Text(
"test",
textAlign: TextAlign.justify,
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.normal),
))
],
)),
)),
);
},
),
),
])),
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论