Leon
Leon

Reputation: 162

Flutter GetX RxList assign issue

Im trying to convert old code to new code syntax. I have a issue with RxList.

enter image description here

So I change postModel.assign(postDetail);

enter image description here

But In my news_detail page How I can access to value?

enter image description here

Upvotes: 2

Views: 4490

Answers (2)

S. M. JAHANGIR
S. M. JAHANGIR

Reputation: 5070

First of all you shouldn''t use postModel as a List as your API clearly returns a single post (NewsModel) by id and not a list of post (List of NewsModel). So using var postModel = <NewsModel>[].obs; is totally unnecessary in my opinion. What you could do is:

final postModel = NewsModel().obs;

And then on API call:

postModel.value = postDetail;

And then on View:

Image.network(controller.postModel.value.imageUrl);

Upvotes: 4

Baker
Baker

Reputation: 28120

postModel is a List.

So you would need to access an item in that list, using an int index.

Something like this:

return Image.network(newsDetailController.postModel[0].imageUrl);

Upvotes: 1

Related Questions