Riverpod – ref.refresh. “refresh” 的值应该被使用。

huangapple go评论52阅读模式
英文:

Riverpod - ref.refresh. The value of 'refresh' should be used

问题

我使用 riverpod 和 flutter。

在我的主屏幕上,我有一个 FutureProvider,它调用 API 服务器,并在页面上显示结果。

在应用程序的各个点上,用户在不同屏幕上进行更改,我从其他屏幕刷新提供程序。像这样

ref.refresh(calendarResponseProvider);

现在,由于某种原因,刷新是灰色的,我得到了这个错误:

Riverpod – ref.refresh. “refresh” 的值应该被使用。

现在,我正在使用另一个屏幕上的刷新值。我做错了什么吗?我应该忽略它吗?

英文:

I'm using riverpod with flutter.

On my main screen I have a FutureProvider which makes a call to the API server, and displays results on the page.

At various points in the app, the user on different screens, makes changes, and I refresh the provider from the other screen. Like this

ref.refresh(calendarResponseProvider);

Now, for some reason, the refresh is in grey, and I get this error:

Riverpod – ref.refresh. “refresh” 的值应该被使用。

Now, I am using the value of refresh on the other screen. Am I doing something wrong? Should I ignore it?

答案1

得分: 8

如果您不使用 refresh() 返回的结果,则使用 invalidate() 方法来重置提供程序的状态。

代码部分不翻译,只提供翻译好的文本。

英文:

If you do not use the result returned by refresh(), then use the invalidate() method to reset the provider state.

Writing:

final newValue = ref.refresh(provider);

is strictly identical to doing:

ref.invalidate(provider);
final newValue = ref.read(provider);

huangapple
  • 本文由 发表于 2023年2月24日 04:49:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75550188.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定