如何清除Riverpod中的所有缓存

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

How to clear all the cache in Riverpod

问题

我已经在Flutter中使用river-pod创建了一个应用程序,但出现的问题是当我从用户1登录然后注销,然后再使用用户2登录时,显示的数据仍然是用户1的。所以我想要更改它,以便显示的数据是用户2的(可能是通过清除缓存,这似乎是我最可行的选项)。

我在Stack Overflow上寻找了一些解决方案,但由于它们已经过时,我无法理解其他解决方案。

英文:

I have created an App in Flutter using river-pod, but the problem arises is when I login from user1 and logout and then log back in using User2, the data shown is still of user1. So i want to change it so that the data shown is of User2 (it can be by clearing the cache which seems like the most viable option for me).

I have looked out for some solutions on Stack-overflow itself but i was unable to catch onto them as they were outdated and I wasn't able to understand the rest of the solutions

答案1

得分: 0

让您的数据依赖于您的用户。类似于:

final userProvider = Provider((ref) => User(...));

// 与用户相关的信息
...
final dataProvider = Provider((ref) {
  ref.watch(userProvider);
  return data;
});
...
final otherDataProvider = Provider((ref) {
  ref.watch(userProvider);
  return otherData;
});
英文:

Make your data dependent on your user. Something like:

final userProvider = Provider((ref) => User(...));

// information relating to the user
...
final dataProvider = Provider((ref) {
  ref.watch(userProvider);
  return data;
});
...
final otherDataProvider = Provider((ref) {
  ref.watch(userProvider);
  return otherData;
});

huangapple
  • 本文由 发表于 2023年2月27日 18:32:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75579317.html
匿名

发表评论

匿名网友

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

确定