I can't seem to figure out how to fix this error. This was previously working but is now producing this error after upgrading to Flutter Null Safety version:
I'm using the screenshot: ^1.0.0-nullsafety.1 package for the ScreenshotController
File _imageFile;
ScreenshotController screenshotController = ScreenshotController();
IconButton(
icon: Icon(Icons.download_sharp),
onPressed: () {
Directory directory;
_requestPermission(Permission.storage);
try {
_imageFile = null;
screenshotController
.capture(delay: Duration(milliseconds: 10))
.then((File image) async {
//print("Capture Done");
setState(() {
_imageFile = image;
});
if (await _requestPermission(Permission.storage)) {
directory = await getExternalStorageDirectory();
String newPath = '';
List<String> folders = directory.path.split('/');
for (int x = 1; x < folders.length; x++) {
String folder = folders[x];
if (folder != 'Android') {
newPath += '/' + folder;
} else {
break;
}
}
newPath = newPath + '/Tinda';
directory = Directory(newPath);
print(directory.path);
} else {
return false;
}
if (!await directory.exists()) {
await directory.create(recursive: true);
}
if (await directory.exists()) {
final result = await ImageGallerySaver.saveImage(
_imageFile.readAsBytesSync(),
quality: 100);
print("File Saved");
print(result);
}
}).catchError((onError) {
print(onError);
});
} catch (e) {
print(e);
}
},
),
Here's some screenshots:
Any guidance will be highly appreciated.
The error is telling you to make the argument passed into you .then
function should be of type Uint8List
instead of File
. This is most likely because sceenshotController.capture
returns a Future<Uint8List>
, so in the .then
, you will have access to the Uint8List
.
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