difference between ref.watch(myProvider.state) and ref.watch(myProvider).state

Viewed 119

I'm watching a provider's state in another provider.

This is my StateProvider.

final counterProvider = StateProvider<int>((ref) => 0);

Now there are two ways to watch this.

final isEvenProvider = Provider<bool>((ref) {
  final counter = ref.watch(counterProvider); // First
  return (counter.state % 2 == 0);
});
final isEvenProvider = Provider<bool>((ref) {
  final counter = ref.watch(counterProvider.state); // Second
  return (counter % 2 == 0);
});

What is the difference between the two?
When should we use which?

0 Answers
Related