MappingHook with Future possible?
Closed this issue · 2 comments
llorenzo commented
When serialising an Image to be part of the json I need to use an async Future:
@override
Future<Object>? beforeEncode(Object? value) async {
var file = XFile(value.toString());
List<int> fileBytes = await file.readAsBytes();
return base64.encode(fileBytes);
}
It throws an error. => Unknown type _Future. Did you forgot to annotate the class or register a custom mapper?
schultek commented
Generally everything will only execute synchronously. When you return a future, that future would be treated as the encoded value instead of awaited. And since there is no mapper for Future, it fails.
You could add a custom mapper for Future but I don't know if that would help you since again the future can't be awaited during the serialization process since everything is synchronous.
llorenzo commented
I now serialize the images beforehand. This, it works for me. Thank you