Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check runtimeType of an object to get object in Map #1023

Closed
KhanhPham0102 opened this issue Dec 20, 2023 · 2 comments
Closed

Check runtimeType of an object to get object in Map #1023

KhanhPham0102 opened this issue Dec 20, 2023 · 2 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@KhanhPham0102
Copy link

I have a problem checking the runtimeType of an object to send through HTTP.

I create a list of objects with map (The objects were generated by freezed).

Map<Type, dynamic> lists = {
Email : Email(),
Password : Password(),
Settings : Settings(),
}

When I check the runtimeType of the object then the result is like this _$EmailImpl, _$PasswordImpl and _$SettingsImpl.

Then I want to get the above object through the key and get an error.

lists[Email] -> Correct
lists[_$EmailImpl] -> Error

So is there any way I can get the base object "Email" instead of "_$EmailImpl".

@rrousselGit
Copy link
Owner

No, that's not feasible.

You probably shouldn't be relying on runtimeType in your case then

@KhanhPham0102
Copy link
Author

I'm using your Freezed library with Chopper library. I need to convert the body to send it. You can see it at the link below.

https://github.com/lejard-h/chopper/blob/develop/converters/converters.md

In convertRequest function, I need convert body to String. The body here could be an Object or a Map or other data types. So, I can only get the Type of body through runtimeType to convert to the correct data type.

Do you have any solution or any idea for my problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants