on<T> static method
StreamSubscription<T>
on<T>(
- void handler(
- T event
- bool handleError = true,
- ErrorCallback? onError,
订阅事件,返回可取消的订阅对象
Implementation
static StreamSubscription<T> on<T>(
void Function(T event) handler, {
bool handleError = true,
ErrorCallback? onError,
}) {
final subscription = instance.on<T>().listen(
(event) {
if (kDebugMode) {
print('[EventBus] Received event: ${event.runtimeType}');
}
_safeRun(() => handler(event), onError: onError);
},
onError: handleError
? (error, stack) {
_safeRun(() => onError?.call(error, stack));
}
: null,
);
return subscription;
}