Back

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

  • 0
  • Android
  • Flutter
Ironman
20 Sep, 2023, 09:32

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

Reference 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();

TypeScript
    },
    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

TL;DR
The error is related to assigning a Uint8List to a parameter that expects a File. The problem seems to be with the capture() method. One possible solution is to convert the Uint8List to a File object before passing it as a parameter. You can do this by using the path_provider package to get the temporary directory and then creating a new File using the Uint8List and the temporary directory. Here's an example of how you can solve the error: ```dart import 'package:path_provider/path_provider.dart'; ... IconButton( onPressed: () async { Uint8List? bytes = await screenshotController.capture();
Drake
20 Sep, 2023, 16:43

Is this related to Appwrite?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more