嗨,我是新手,尝试编写我的第一个应用程序,我该如何解决RenderFlex错误,我想显示将两个textFields放入单独的容器中 我第二个列表也有这个问题。我还打算显示列表中的最新项目,但实际上,它保留在BottomNavigation层下,并且没有完全显示。我的代码在这里,谢谢您的指导
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 32, left: 16, right: 16),
child: Row(
children: <Widget>[
Container(
height: 45,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 10.0,
color: Colors.black.withOpacity(.1),
offset: Offset(3.0, 3.0),
),
],
),
child: RaisedButton.icon(
onPressed: () {},
icon: Icon(Icons.arrow_drop_down_circle),
label: Text("انتخاب موقعیت"),
color: Color(0XffF1F2F3),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
),
)),
SizedBox(
width: 20,
),
Container(
height: 50,
width: MediaQuery.of(context).size.width / 1.899,
child: TextField(
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(top: 5),
hintText: "جستوجو آگهی ...",
prefixIcon: Icon(
Icons.search,
color: (Colors.grey),
),
filled: true,
fillColor: Color(0XffF1F2F3),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide.none)),
),
)
],
),
),
Container(
height: 130,
child: ListView.builder(
itemCount: 10,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8),
child: new Container(
width: 70,
height: 70,
decoration: new BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 8.0,
color: Colors.black38
.withOpacity(.5),
offset: Offset(2.0, 2.0),
),
],
border: Border.all(
width: 1,
color: Colors.red,
style: BorderStyle.solid),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.yellow,
Colors.amber,
Colors.orangeAccent,
Colors.deepOrange,
Colors.redAccent,
Colors.red
]),
shape: BoxShape.circle,
image: new DecorationImage(
image: new NetworkImage(
"https://cdn0.iconfinder.com/data/icons/classic-cars-by-cemagraphics/512/camaro_512.png")))),
),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"خودرو",
style: TextStyle(
fontSize: 15, color: Colors.black87),
),
),
],
),
);
}),
),
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: ListView.builder(
itemCount: 10,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(
left: 8, right: 8, bottom: 12),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 9.0,
color: Colors.black54.withOpacity(.3),
offset: Offset(5.0, 5.0),
),
],
color: Color(0XffF3F3F4),
borderRadius: BorderRadius.circular(10),
border: Border.all(
width: 1,
color: Color(0XffF3F3F4),
style: BorderStyle.solid),
),
child: Row(
children: <Widget>[
Container(
height: 200,
width: MediaQuery.of(context).size.width /
2.1,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topRight:
const Radius.circular(10.0),
bottomRight:
const Radius.circular(10.0)),
image: new DecorationImage(
fit: BoxFit.fill,
image: new NetworkImage(
"https://s101.divarcdn.com/static/pictures/1576001315/QXv36p38.jpg")))),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
top: 10,
left: 8,
right: 8,
bottom: 60),
child: Text(
"سمند سفید مشابه صفر",
style: TextStyle(
fontSize: 18,
color: Colors.black),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"29000000 تومان",
style: TextStyle(
fontSize: 15,
color: Colors.black),
),
),
Padding(
padding: const EdgeInsets.only(
right: 8,
left: 8,
top: 40,
bottom: 10),
child: Row(
children: <Widget>[
Text(
"دقایقی پیش در شیراز",
style: TextStyle(
fontSize: 13,
color: Colors.black),
),
SizedBox(
width: 20,
),
Text(
"خودرو",
style: TextStyle(
fontSize: 11,
color: Colors.black),
),
],
),
),
],
)
],
),
));
},
),
),
),
],
),
);
}
答案 0 :(得分:0)
您已将整个内容包装在Column
中,这引起了异常。列窗口小部件不会滚动,并且由于您已经singlechildscrollview
会滚动内容,所以Column
不允许它。因此,要解决此问题,只需用ListView
包裹您的全身内容,如下所示:
return Scaffold(
resizeToAvoidBottomPadding: false,
body: ListView( // use ListView instead of Column
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 32, left: 16, right: 16),
child: Row(
...
结果:
希望这能回答您的问题。