0
enum ConnectivityResult {
  bluetooth,  
  wifi,
  ethernet,
  mobile,
  none
}
    

final connectivityProvider = StreamProvider<ConnectivityResult>((ref){
    ...
})

final repoProvider = FutureProvider<List>((ref) async {
  ref.watch(
    connectivityProvider.selectAsync(
      // WHAT DO TO HERE.
      (data) => ConnectivityResult.wifi,
    ),
  );
  ...
});

I want to listen only the "ConnectivityResult.wifi" to trigger rebuild for repoProvider.

  • something like `ref.watch(connectivityProvider.select((e) => e == ConnectivityResult.wifi))` which will flip between true and false depending on whether the connection is wifi or not. – Randal Schwartz Oct 06 '22 at 04:52
  • @RandalSchwartz I've tried that. It doesn't work. – Thet Lwin Lwin Oct 06 '22 at 05:52
  • You'll have to be more specific than "it doesn't work". – Randal Schwartz Oct 06 '22 at 16:00
  • The app is connected to the wifi when it is started and everything is fine. When wifi is disconnected, I don't want to trigger the future provider. But, when user reconnect to wifi, I want to run that provider. The equality check as you mention trigger the provider in both scenarios. – Thet Lwin Lwin Oct 06 '22 at 18:24
  • Strange enough. It listens both ConnectivityResult.none case and ConnectivityResult.wifi case. – Thet Lwin Lwin Oct 06 '22 at 18:27
  • I think you misunderstand. It will trigger the listen when that expression changes. From true to false, and from false to true. So yes, it will trigger on both... it's up to you to do something with the current value. – Randal Schwartz Oct 06 '22 at 20:13
  • yeah. I just want only wifi value to trigger the provider. My question is a bit incomplete. – Thet Lwin Lwin Oct 07 '22 at 01:38

1 Answers1

0

Thanks to Randal comments and after reading the documentation, the problem is solved. Thanks a lot.

  • Please don't add "thank you" as an answer. Instead, **[accept the answer](https://stackoverflow.com/help/accepted-answer)** that you found most helpful. - [From Review](/review/late-answers/33721321) – V-rund Puro-hit Jan 31 '23 at 07:01