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

Make MediaItem from JSON #352

Closed
1 task
bemi2018 opened this issue Jun 8, 2020 · 3 comments
Closed
1 task

Make MediaItem from JSON #352

bemi2018 opened this issue Jun 8, 2020 · 3 comments
Assignees
Labels
1 backlog question Further information is requested

Comments

@bemi2018
Copy link

bemi2018 commented Jun 8, 2020

Checklist

  • [ x] The question is not already in the FAQ.
  • The question is not too narrow or specific to a particular application.

Suggested Question

How can i make a MediaItem list from Json file? or do i need always to hard code all the MediaItems?
Thank you in advance.

@bemi2018 bemi2018 added 1 backlog question Further information is requested labels Jun 8, 2020
@Marekkon5
Copy link

You can use the MediaItem.fromJson function. If you want to restore a JSON list you can try using map:

List<MediaItem> mediaItemList = jsonList.map<MediaItem>((json) => MediaItem.fromJson(json)).toList();

@ryanheise
Copy link
Owner

Speaking of which, this proposal is a great idea:

dart-lang/language#216

It's unfortunate that you currently can't do this:

jsonList.map(MediaItem.fromJson).toList()

which would be much more concise. I could actually change the fromJson constructor to instead be a static method, and then you'd be able to write code like that.

As to whether this question should be added to the FAQ, if I added general programming questions to the FAQ, that would make the document less useful for its intended purpose, and I do not intend to do so.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants