jonataslaw / jonataslaw/get_server

upload file and got cast error

Open
#68 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
484
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Upload file to server and got cast error in file widget.dart @jonataslaw

Error is
`_CastError (type 'Future?>' is not a subtype of type 'FutureOr>' in type cast)`

Function is
```
@override
Future file(String name, {Encoding encoder = utf8}) async {
final payload = await (request.payload(encoder: encoder)
as FutureOr>);
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 file(String name, {Encoding encoder = utf8}) async {
try {
final payload = await (request.payload(encoder: encoder)
as FutureOr?>);

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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.