flutter_hooks
flutter_hooks copied to clipboard
`useOnStreamChange` doesn't update on callback changes
Describe the bug
When the callback reference is updated, the useOnStreamChange hook doesn't update.
final onDataCallback = useCallback((int data) {
print(multiplierValue * data);
}, [multiplierValue]); // dependency triggers a callback ref change
useOnStreamChange(stream, onData: onDataCallback);
Cause:
https://github.com/rrousselGit/flutter_hooks/blob/319679b4ff8e4e224b3d9c29fd138623f750a24d/packages/flutter_hooks/lib/src/async.dart#L396-L397
The hook implementation only check for changes of stream and cancelOnError parameters, other callback parameters are ignored.
To Reproduce
Reproducible sample: https://dartpad.dev/?id=cdc8f5006a2e15f0761504cba0ab81cb
Expected behavior
When the callback reference is updated, the hook should _unsubscribe() and _subscribe() again to update the callback reference; ~~or use some kind of callback wrapper to always provide the latest callback reference~~ (doesn't work).
I can also provide the PR if this behavior is indeed a bug.