Home > Enterprise >  Image picker scanned to null flutter
Image picker scanned to null flutter

Time:10-15

File _image; final picker = ImagePicker();

Future getImage() async {
  final pickedFile = await picker.getImage(source: ImageSource.camera);

  setState(() {
    if (pickedFile != null) {
      _image = File(pickedFile.path);
    } else {
      print('No image selected.');
    }
  });
}

output:

D/MediaScannerConnection(16161): Scanned /storage/emulated/0/Android/data/com.xxxx.xxxx/files/Pictures/9d9ed6a1-292c-428a-bf24-38ea1a58742c6940060118053310767.jpg to null

CodePudding user response:

Sometimes this error show up because you need to clean your build folder. Try to do flutter clean and rebuild again.

CodePudding user response:

Try this:

PickedFile pickedFile = await picker.getImage(source: ImageSource.camera);

if (pickedFile == null) {
  return null;
}

Directory appDirectory = await getApplicationDocumentsDirectory();
File newImage = File(appDirectory.path   'fileName');
newImage.writeAsBytes(File(pickedFile.path).readAsBytesSync());

setState(() {
  _image = newImage;
  print(newImage.path   ' test');
});
  • Related