Flutter, Dart: The value of the local variable'uint8list' isn't used. Is displayed even though the declared variable is used

Viewed 1797
//main.dart
// The declared uint8list turns gray (android studio).
//The value of the local variable 'uint8list' isn't used.
//It is displayed as above. It is considered unused.

                  var uint8list;  //←string color is gray.
                  var file;
                  var bytes;
                  Widget sumb=Container(width:100);

                  try{
                      uint8list = await VideoThumbnail.thumbnailFile(
                      video: tempurl,
                      thumbnailPath: (await getTemporaryDirectory()).path,
                      imageFormat: ImageFormat.WEBP,
                      maxHeight: 200,
                      // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
                      quality: 75,
                    );
                  }catch(e){

                  }


                  uint8list="";  //←← Described as a trial. Even with this, the declaration part remains gray.

I'm trying to create a thumbnail from a video file uploaded to cloud_storage in firebase, but on the way I got an unfamiliar behavior.

I'm using the VideoThumbnail.thumbnailFile method from the VideoThumbnail package. This method is an asynchronous method that returns Future , but sometimes it fails to create a thumbnail and an error appears, so I'm trying to write exception handling.

In the above code, uint8list is grayed out and the message "Variables are not used" appears, but I think that it is clearly used even considering the scope.

I think it's possible to access variables in the outer scope from inside the try block {}, in Dart lang. Am I wrong?

1 Answers

In the above code, uint8list is grayed out and the message "Variables are not used" appears, but I think that it is clearly used even considering the scope.

You are misinterpreting the warning. The value isn't used. You are assigning values to it. But you never care and never read those values. So it's pointless to have this variable.

The warning will vanish, once you actually use the variable and read what you assigned to it.

Related