I have initialized a File type variable in my Flutter Dart class as:
late File _image;
then I have assigned picked image from gallery to this variable eg.
_image = File(pickedFile.path);
I have displayed this image by using _image variable on the screen which is ok. I have a button delete button, which is used to remove selected image then need to re-pick new image. So I will have to reset this _image variable on delete button click.
Is there anyone who can help and suggest me. How can I reset this _image variable in NULL SAFETY in dart / flutter. Thanks a lot.
Instead of using late File _image; you can use File? _image; which would allow null for assignment. If you use some operation on _image make sure to use ?. operator (_image?.something).
There's no way to declare late File _image; with import 'dart:io'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With