Why can't I use .value in a list using GetX?

Issue

I’m learning to use getx as Flutter state manager and I can’t use .value in a list variable, even using .obs to make the list observable.

final List<TaskModel> _taskList = <TaskModel>[].obs;

  get taskList => this._taskList.**value**;

The getter ‘value’ isn’t defined for the type ‘List’.

What is the correct way to do it with lists?

Solution

Lists are reactive (Rx) by default. Although you need to make them observable with .obs, you don’t need to return .value in your getter.
Instead, you can directly return your private list:

get taskList => this._taskList;

And whenever your _taskList changes, it will automatically reflect on your observer widget (Obx, GetX).

Answered By – S. M. JAHANGIR

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *