riverpod - Provider listener body is not triggered when switching between two screens that listen to the same provider - Stack O

admin2025-04-16  4

I have Flutter app with two screen: ScreenA and ScreenB. I am using RiverPod. I am listening to the same provider in both screens using ref.listen(). I run into a problem when navigating between both screens. Here is an example that cause problem.

  • Initially the app starts at ScreenA.
  • While in ScreenA, I update the provider. The listener in ScreenA is trigged as expected
  • I navigate to ScreenB. To my surprise, the body of the provider listener in ScreenB is not called when I enter into ScreenB. That means that ScreenB will not know the state of the provider when navigating from ScreenA to ScreenB.
  • If I navigate to ScreenB from ScreenC which does not listen to the the same provider, the body of the provider listener in ScreenB is triggered with no problems.

Is this a feature or a bug?

转载请注明原文地址:http://anycun.com/QandA/1744736824a86899.html