英文:
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;
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论