Open tang85 opened 3 years ago
Upload file to server and got cast error in file widget.dart @jonataslaw
Error is _CastError (type 'Future<Map<dynamic, dynamic>?>' is not a subtype of type 'FutureOr<Map<dynamic, dynamic>>' in type cast)
_CastError (type 'Future<Map<dynamic, dynamic>?>' is not a subtype of type 'FutureOr<Map<dynamic, dynamic>>' in type cast)
Function is
@override Future<MultipartUpload> file(String name, {Encoding encoder = utf8}) async { final payload = await (request.payload(encoder: encoder) as FutureOr<Map<dynamic, dynamic>>); final multiPart = await payload[name]; if (multiPart is MultipartUpload) { return multiPart; } else { Get.log('Incorrect format, upload the file as Multipart/formdata', isError: true); return MultipartUpload(null, null, null, null); } }
Maybe we should wrap function's body with try..catch as below.
@override Future<MultipartUpload> file(String name, {Encoding encoder = utf8}) async { try { final payload = await (request.payload(encoder: encoder) as FutureOr<Map<dynamic, dynamic>?>); final multiPart = await payload![name]; if (multiPart is MultipartUpload) { return multiPart; } else { Get.log('Incorrect format, upload the file as Multipart/formdata', isError: true); return MultipartUpload(null, null, null, null); } } catch (e) { return MultipartUpload(null, null, null, null); } }
// I love get_server,It's Great!
Hello @tang85 ! did you find any solution ?
Upload file to server and got cast error in file widget.dart @jonataslaw
Error is
_CastError (type 'Future<Map<dynamic, dynamic>?>' is not a subtype of type 'FutureOr<Map<dynamic, dynamic>>' in type cast)
Function is
Maybe we should wrap function's body with try..catch as below.
// I love get_server,It's Great!