我是flutter的新手,所以当我尝试从api获取图像并将它们添加到列表中然后使用时,我无法解决页面视图异常列表中的 foreach 循环以在 carousel pro
中显示图像我的代码是--
if (widget.user_id != null) {
body = jsonEncode(<String, dynamic>{
'respObj': {
"Id": widget.user_id,
},
});
} else {
body = jsonEncode(<String, dynamic>{});
}
final http.Response response = await http.post(
'api url',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: body,
);
var res = json.decode(response.body);
if (response.statusCode == 200) {
res["resplist"].forEach((element){
setState(() {
images.add(element["categoryBanner"]);
});
});
images.forEach((element) {
setState(() {
_img.add(NetworkImage(element));
});
});
} else {
images==null;
}
Widget imageCrousel = Container(
height: 140.0,
child: Carousel(
indicatorBgPadding: 5.0,
dotIncreasedColor: Colors.red,
dotColor: Colors.white,
boxFit: BoxFit.cover,
images:_img==null?
[AssetImage('assets/defimg.jpg')]:_img,
autoplay: false,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 1000),
),
);
异常---
Page value is only available after content dimensions are established.
'package:flutter/src/widgets/page_view.dart':
Failed assertion: line 373 pos 7: 'pixels == null || (minScrollExtent != null && maxScrollExtent != null)'
答案 0 :(得分:0)