Syed Rehan
Syed Rehan

Reputation: 1204

Flutter Consumer not rebuilding UI using riverpod StateNotifierProvider

Its my 1st time using riverpod and for practice purposes, I'm making to-do app. I'm using StateNotifierProvider and it's not updating the ListViewBuilder but updating the length of items but not showing that item. Please Guide me, Here is the SC of StateNotifier enter image description here

and here is the calling method to call add method here is the SC enter image description here

and here is the UI UPDATING THE NUMBERS OF items but not updating the list. enter image description here

Upvotes: 0

Views: 284

Answers (2)

Syed Rehan
Syed Rehan

Reputation: 1204

I solved my issue:

  void addtask(String? newtask) {
final task = TaskModel(name: newtask!);
state = [...state, task];

}

Upvotes: 0

MSARKrish
MSARKrish

Reputation: 4094

Modify addTask method like this.

void addTask(String newTask)
{
  state=[...state,TaskModel(name: newTask)];
}

For more information check official documentation for StateNotifierProvider here

Upvotes: 1

Related Questions