0

Hello I am having an issue where when trying to set the type of a variable mediainfo flutter requires that VideoCompress.compressVideo(); returns a type of Future<MediaInfo>

Syntax Error is as follows A value of type 'Future<MediaInfo>' can't be assigned to a variable of type 'MediaInfo'.

And when using VideoCompress.getMediaInfo(file) it seems to not return a MediaInfo type as when I try to assign it to a variable it fails to provide the .path method.

Here is an example of the code.

static Future<MediaInfo> compressVideo(file, context) async{
    await VideoCompress.compressVideo(file,
        quality: VideoQuality.HighestQuality, deleteOrigin: true);
    final info = VideoCompress.getMediaInfo(file);

    return info;

Attempt of trying to access .path click me

JoeCodes
  • 35
  • 6

1 Answers1

0

that's because compressVideo function doesn't return MediaInfo, it returns Future so you need to await for it.

final info = await VideoCompressApi.compressVideo(filePath, context);
setState((){
  compressedInfo = info.path;
});

Edit: you can also use:

VideoCompressApi.compressVideo(filePath, context).then((info) {
  setState(() => compressedInfo = info.path);
});
mohamed.oussous
  • 410
  • 2
  • 5
  • Thank you, it worked. Hope you have a great week. – JoeCodes May 30 '22 at 12:17
  • if you have the time I would appreciate if you would take a look at this question it relates to the answer you provided (https://stackoverflow.com/questions/72449555/flutter-error-when-using-null-check-operator-with-android-emulator) – JoeCodes May 31 '22 at 15:15