Reputation: 162
Im trying to convert old code to new code syntax. I have a issue with RxList.
So I change postModel.assign(postDetail);
But In my news_detail page How I can access to value?
Upvotes: 2
Views: 4490
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
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