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