我想在“ body:”部分的“ Column”下查看Carousel,但收到此错误: 在performResize()期间引发了以下断言:
水平视口的高度不受限制。
视口在横轴上扩展以填充其容器,并约束其子代以使其在横轴上的范围匹配。在这种情况下,将为水平视口提供无限量的垂直空间以进行扩展。 相关的引起错误的小部件是:
ListView文件:///Users/ahmed/AndroidStudioProjects/flutter_app_service2/lib/screens/home/profile_list.dart:27:21 引发异常时,这是堆栈:
... 引发异常时,正在处理以下RenderObject:RenderViewport#d699b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE ...需要合成 ... parentData :(可以使用大小) ...约束:BoxConstraints(0.0 <= w <= 414.0,0.0 <= h <= Infinity) ...大小:MISSING ... axisDirection:右 ... crossAxisDirection:下 ...偏移量:ScrollPositionWithSingleContext#209bd(偏移量:0.0,范围:null..null,视口:null,ScrollableState,BouncingScrollPhysics,IdleScrollActivity#ac774,ScrollDirection.idle) ...锚点:0.0 RenderObject:RenderViewport#d699b需求布局需求油漆涂料需求组成位更新 需要合成 parentData :(可以使用大小) 约束:BoxConstraints(0.0 <= w <= 414.0,0.0 <= h <= Infinity) 尺寸:MISSING axisDirection:右 crossAxisDirection:向下 偏移量:ScrollPositionWithSingleContext#209bd(偏移量:0.0,范围:null..null,视口:null,ScrollableState,BouncingScrollPhysics,IdleScrollActivity#ac774,ScrollDirection.idle) 锚点:0.0 ...中心孩子:RenderSliverPadding#201ae需要布局的需要油漆需要组合的位更新 ... parentData:paintOffset =偏移量(0.0,0.0) ...限制:MISSING ...几何:null ...填充:EdgeInsets.zero ... textDirection:ltr ...孩子:RenderSliverList#b683f NEEDS-LAYOUT NEEDS-PAINT ... parentData:paintOffset =偏移量(0.0,0.0) ...限制:MISSING ...几何:null ...没有孩子活着
这是我在家中的代码:
body: Column(
children: <Widget>[
ProfileList(),
],
),
这是ProfileList,它指向ProfileCarousel:
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,
);
}
}
这是ProfileCarousel:
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),
),
],
)
],
),
)
],
),
)
],
),
);
}
}
答案 0 :(得分:1)
我设法通过用SizedBox小部件包装ProfileList并为其设置适当的高度来找到解决方案:
body: Column(
children: <Widget>[
SizedBox(height: 500, child: ProfileList()),
],
),
答案 1 :(得分:1)
简单地给 ProfileList()
提供区域,以便它可以正确查看
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
child: ProfileList(),
),
),