1

I'm making a feature to let user choose and upload their images on my platform. Here is the code of the choosing part. However, I got the error like the title because the running type of chosen Image is '_File' instead of File. The function MediaPicker.pickMediaFromLocal is also used in other places but it works properly and return File instead of _File. I have searched, read the source code, and tried to cast it as type File but it didn't work. Can anyone help me with this.

enter image description here

enter image description here

enter image description here

Hoangdz
  • 152
  • 1
  • 14
  • Check your library imports and make sure there is no other file imports – Nidheesh MT Aug 22 '21 at 07:56
  • What is `AssetEntity`? What package does `MediaPicker` come from? Most likely you have `AssetEntity.file` does not return a `dart:io` `File` object, which is expected by `FileImage`. Also, don't post code as images. – jamesdlin Aug 22 '21 at 08:08
  • I have checked my library before. I'm currently using File from 'dart:io', but there is another library ('package:file/file.dart';) that makes me confused about which one is correct. – Hoangdz Aug 22 '21 at 08:08
  • `package:file` provides an abstraction layer to make testing easier. Its `File` class derives from `dart:io`'s `File` class and therefore can be used where a `dart:io` `File` is expected. If you use both, I recommend using `import 'dart:io' as io;` and using an `io.` prefix so that you can easily distinguish between them. – jamesdlin Aug 22 '21 at 08:12
  • thanks for the advice, but it still returns a _File type instead of File – Hoangdz Aug 22 '21 at 08:19
  • You still haven't answered the questions. My advice wasn't supposed to change the runtime type; `_File` is just some implementation class for some other `File` class, but it's hard to say exactly what `File` class it is without more information. – jamesdlin Aug 22 '21 at 09:28

0 Answers0