Home > Mobile >  RangeError (index): Invalid value: Valid value range is empty: 0 - Flutter
RangeError (index): Invalid value: Valid value range is empty: 0 - Flutter

Time:08-22

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. 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.

CodePudding user response:

Seems like you are not getting any data on camera. You can skip the error like,

 if(tasks.isNotEmpty)onNewCameraSelected(camera[0]);

And for N number

 if(tasks.length>=n-1)onNewCameraSelected(camera[n]);

CodePudding user response:

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

  • Related