dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

The argument type 'Uint8List' can't be assigned to the parameter type 'File'

Open ahkharsha opened this issue 2 years ago • 2 comments
trafficstars

[The argument type 'Uint8List' can't be assigned to the parameter type 'File'.dartargument_type_not_assignable Uint8List? bytes Type: Uint8List?]

Image - (https://i.stack.imgur.com/iSbTP.png)

My Code:

IconButton(
    onPressed: () async {
        Uint8List? bytes = await screenshotController.capture();
        imageProvider.changeImage(bytes!);
        if (!mounted) return;
        Navigator.of(context).pop();

        },
        icon: const Icon(Icons.done),
)

Can someone suggest how to solve this error please? I am a beginner

I tried to pass bytes as parameter with null check, but this isn't working

https://www.youtube.com/watch?v=qXU5o8v4DX0&ab_channel=KODDev

I was coding after which this yt video. It seems to be working for him (Time stamp - 52:25), but not for me.

ahkharsha avatar Sep 19 '23 22:09 ahkharsha

@Hxrsha-x what you want to do is write the uint8list bytes to a file, to do this you need to create a file first and then write to it.

final bytes = await screenshotController.capture();
final temp = await getTemporaryDirectory();
final file = File('${temp.path}/example.png'); // I assume you're trying to get an image
await file.writeAsBytes(bytes!);

imageProvider.changeImage(file);

CoderNamedHendrick avatar Sep 25 '23 02:09 CoderNamedHendrick

@Hxrsha-x what you want to do is write the uint8list bytes to a file, to do this you need to create a file first and then write to it.

final bytes = await screenshotController.capture();
final temp = await getTemporaryDirectory();
final file = File('${temp.path}/example.png'); // I assume you're trying to get an image
await file.writeAsBytes(bytes!);

imageProvider.changeImage(file);

@Hxrsha-x have you tried this? Does the issue still persist?

CoderNamedHendrick avatar Nov 07 '23 08:11 CoderNamedHendrick