Search code examples
flutterassignflutter-getx

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


Solution

  • 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);