简体   繁体   English

Flutter 消费者不使用 riverpod StateNotifierProvider 重建 UI

[英]Flutter Consumer not rebuilding UI using riverpod StateNotifierProvider

Its my 1st time using riverpod and for practice purposes, I'm making to-do app.这是我第一次使用 riverpod,出于练习目的,我正在制作待办事项应用程序。 I'm using StateNotifierProvider and it's not updating the ListViewBuilder but updating the length of items but not showing that item.我正在使用 StateNotifierProvider 并且它不是更新 ListViewBuilder 而是更新项目的长度但不显示该项目。 Please Guide me, Here is the SC of StateNotifier请指导我,这是 StateNotifier 的 SC 在此处输入图像描述

and here is the calling method to call add method here is the SC这是调用添加方法的调用方法,这里是 SC 在此处输入图像描述

and here is the UI UPDATING THE NUMBERS OF items but not updating the list.这是更新项目数量但不更新列表的用户界面。 在此处输入图像描述

Modify addTask method like this.像这样修改 addTask 方法。

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

For more information check official documentation for StateNotifierProvider here有关详细信息,请在此处查看StateNotifierProvider的官方文档

I solved my issue:我解决了我的问题:

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

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM