listenWithPrevious<T> method
Listen a pod with previous value
Implementation
void listenWithPrevious<T>(
Pod<T> pod,
void Function(T? previous, T next) listener,
) {
final container = PodScope.of(this)..get<T>(pod);
_listeners.putIfAbsent('$_listenWithPrevious${pod.hashCode}$hashCode', () {
final callbackWrapper = _CallbackWrapper<T>();
final cancelPodSubscribe =
container.subscribeWithPrevious<T>(pod, (previous, next) {
listener(previous, next);
});
final modalRoute = ModalRoute.of(this);
if (modalRoute != null) {
Future<bool> willPopCallback() {
WidgetsBinding.instance.addPostFrameCallback((_) {
cancelPodSubscribe();
modalRoute
.removeScopedWillPopCallback(callbackWrapper.willPopCallback!);
_listeners.remove('$_listenWithPrevious${pod.hashCode}$hashCode');
});
return Future.value(true);
}
callbackWrapper.willPopCallback = willPopCallback;
modalRoute.addScopedWillPopCallback(callbackWrapper.willPopCallback!);
}
return null;
});
}