[Dart] [dio] Error on nullable file
See original GitHub issueThis definition:
/api/v1/user:
post:
operationId: saveProfile
description: ""
requestBody:
required: true
content:
multipart/form-data:
schema:
"$ref": "#/components/schemas/UserUpdate"
responses:
"200":
description: All good
content:
application/json:
schema:
"$ref": "#/components/schemas/User"
tags:
- user
UserUpdate:
type: object
required:
- id
- email
- lang
properties:
id:
type: integer
email:
type: string
format: email
firstname:
type: string
nullable: true
lang:
type: string
lastname:
type: string
nullable: true
mobile:
type: string
nullable: true
password:
type: string
nullable: true
avatar:
type: string
format: binary
nullable: true
Gives this generation:
_bodyData = FormData.fromMap(<String, dynamic>{
r'id': encodeFormParameter(_serializers, id, const FullType(int)),
r'email': encodeFormParameter(_serializers, email, const FullType(String)),
r'firstname': encodeFormParameter(_serializers, firstname, const FullType(String)),
r'lang': encodeFormParameter(_serializers, lang, const FullType(String)),
r'lastname': encodeFormParameter(_serializers, lastname, const FullType(String)),
r'mobile': encodeFormParameter(_serializers, mobile, const FullType(String)),
r'password': encodeFormParameter(_serializers, password, const FullType(String)),
r'avatar': MultipartFile.fromBytes(avatar, filename: r'avatar'),
});
So it doesn’t compile because avatar (and other fields too but look null only avatar doesn’t compile) can be null. A correct generation would be:
_bodyData = FormData.fromMap(<String, dynamic>{
r'id': encodeFormParameter(_serializers, id, const FullType(int)),
r'email': encodeFormParameter(_serializers, email, const FullType(String)),
r'firstname': encodeFormParameter(_serializers, firstname, const FullType(String)),
r'lang': encodeFormParameter(_serializers, lang, const FullType(String)),
r'lastname': encodeFormParameter(_serializers, lastname, const FullType(String)),
r'mobile': encodeFormParameter(_serializers, mobile, const FullType(String)),
r'password': encodeFormParameter(_serializers, password, const FullType(String)),
if (avatar != null)
r'avatar': MultipartFile.fromBytes(avatar, filename: r'avatar'),
});
I have tested with openapi jar 5.1.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Flutter| Dio : Invalid argument(s) (value): Must not be null
myPrefs doesn't seem to be initialized !!! Try: Future login() async { Dio dio = new Dio(); var myPrefs = await SharedPreferences.
Read more >dio | Dart Package - Pub.dev
A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout etc. Get started #.
Read more >[Solved] Null check operator used on a null value
In this example, we are going to show you how to show you the cause and solution of the "Null check operator used...
Read more >Futures and error handling | Dart
Solution: Using Future.sync() to wrap your code. A common pattern for ensuring that no synchronous error is accidentally thrown from a function is...
Read more >[SOLVED] Flutter : Cannot run with sound null safety, because ...
If you want run your project with --no-sound-null-safety so now you add this line your main.dart file in top(first line) with comment.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah I guess I will have to change my shitty API… Because it like
/api/v1/dashboard/room/null
currently 😕 Thanks for the inputs!@jaumard Any new input here?