riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

2.0-dev "listenSelf" on StateNotifier should track the state not notifier

Open rich-j opened this issue 2 years ago • 0 comments

2.0.0-dev.4 introduces listenSelf on providers. When used with a StateNotifierProvider the arguments to the listenSelf function are typed for the notifier and not the state. We were expecting that the listenSelf would track state changes - especially since a likely pattern already provides access to the notifier.

final aProvider = StateNotifierProvider<ANotifier, AState>((ref) {
  final aNotifier = ANotifier();
  ref.listenSelf((ANotifier? previous, ANotifier notAState) {});  // <-- expecting this to track state, have the notifier in scope
  return aNotifier;
});

rich-j avatar Mar 19 '22 02:03 rich-j