Listview 水平视口被赋予无限高
我想在“body:”部分的列下查看旋转木马,但收到以下错误: performResize期间引发了以下断言: 水平视口被赋予无限高 视口在横轴上展开以填充其容器,并约束其子视口以匹配其在横轴上的范围。在本例中,为水平视口提供了无限的垂直空间来展开。 导致错误的相关小部件是: 列表视图file:///Users/ahmed/AndroidStudioProjects/flutter_app_service2/lib/screens/home/profile_list.dart:27:21 引发异常时,这是堆栈: 0 RenderViewport.performResize。包:颤振/src/rendering/viewport.dart:1289:15 1 RenderViewport.performResize包:flatter/src/rendering/viewport.dart:1301:6 2 RenderObject.layout包:flift/src/rendering/object.dart:1746:9 3 RenderProxyBoxMixin.performLayout包:颤振/src/rendering/proxy_盒。dart:110:13 4 RenderObject.layout包:flift/src/rendering/object.dart:1767:7 。。。 引发异常时正在处理以下RenderObject:RenderViewportd699b需要-LAYOUT需要-PAINT需要-COMPOSITING-BITS-UPDATE ... 需要合成 ... parentData:可以使用大小Listview 水平视口被赋予无限高,listview,flutter,dart,carousel,Listview,Flutter,Dart,Carousel,我想在“body:”部分的列下查看旋转木马,但收到以下错误: performResize期间引发了以下断言: 水平视口被赋予无限高 视口在横轴上展开以填充其容器,并约束其子视口以匹配其在横轴上的范围。在本例中,为水平视口提供了无限的垂直空间来展开。 导致错误的相关小部件是: 列表视图file:///Users/ahmed/AndroidStudioProjects/flutter_app_service2/lib/screens/home/profile_list.dart:27:21 引发异常
... 约束:BoxConstraints0.0我只需用SizedBox小部件包装ProfileList并给它一个适当的高度,就找到了解决方案:
body: Column(
children: <Widget>[
SizedBox(height: 500, child: ProfileList()),
],
),
给ProfileList指定一个区域很简单,这样就可以正确地查看它了
返回脚手架
主体:容器
宽度:double.infinity,
高度:双无限,
child:ProfileList,
,
,
class _ProfileListState extends State<ProfileList> {
@override
Widget build(BuildContext context) {
final profiles = Provider.of<List<Profile>>(context);
profiles.forEach((profile) {
print(profile.firstName);
print(profile.lastName);
print(profile.country);
print(profile.city);
print(profile.imgUrl);
});
return ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
},
itemCount: profiles.length,
);
}
}
class ProfileCarousel extends StatelessWidget {
final Profile profile;
ProfileCarousel({this.profile});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(10.0),
width: 210.0,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 6.0,
),
],
),
child: Stack(
children: <Widget>[
Hero(
tag: profile.imgUrl,
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image(
height: 180.0,
width: 180.0,
image: NetworkImage(profile.imgUrl),
),
),
),
Positioned(
left: 10.0,
bottom: 10.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
profile.firstName,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 24.0,
letterSpacing: 1.2,
color: Colors.white),
),
Row(
children: <Widget>[
Icon(
Icons.arrow_upward,
size: 10.0,
color: Colors.white,
),
SizedBox(width: 5.0),
Text(
profile.city,
style: TextStyle(color: Colors.white),
),
],
)
],
),
)
],
),
)
],
),
);
}
}
body: Column(
children: <Widget>[
SizedBox(height: 500, child: ProfileList()),
],
),