[英]RangeError (index): Invalid value: Valid value range is empty: 0 - Flutter
I am building demo of camera(including, taking picture, save in gallery), but I am getting error of RangeError (index): Invalid value: Valid value range is empty: 0 .我正在构建相机演示(包括拍照、保存在画廊中),但出现RangeError (index): Invalid value: Valid value range is empty: 0错误。 I tried to solve in different ways but I could not.我试图以不同的方式解决,但我做不到。 If you have any solution so, let me know.如果您有任何解决方案,请告诉我。
Error is occuring because of below code由于以下代码而发生错误
List<CameraDescription> camera = [];
. .
class _CameraScreenState extends State<CameraScreen>
with WidgetsBindingObserver{
_ _ _ _ _ _ _
@override
void initState() {
onNewCameraSelected(camera[0]);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
_ _ _
);
}
}
Thanks in advance.提前致谢。
Seems like you are not getting any data on camera
.好像您没有在camera
上获得任何数据。 You can skip the error like,您可以跳过错误,例如,
if(tasks.isNotEmpty)onNewCameraSelected(camera[0]);
And for N number对于 N 号
if(tasks.length>=n-1)onNewCameraSelected(camera[n]);
Usually RangeError (index): Invalid value: Valid value range is empty: 0 is generated whenever you try to call an empty or null list possible there is no data filed in your List通常RangeError(索引):无效值:有效值范围为空:每当您尝试调用空列表或 null 列表时生成 0可能您的列表中没有数据归档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.