maybeOf<T> method
Reactively discovers and observes an optional ancestor BloomProvider<T> within context.
Connects BloomBuildContextProviderExtension.maybeBloomOf with this BloomVia tracking scope in a single,
fluent call, eliminating nested via(context.maybeBloomOf<T>()) boilerplate.
context: The active BuildContext to locate the ancestor provider from.
Exact Type Resolution:
- Lookup matches the exact reified type
T. Subtypes or base classes do not match.
Ensures:
- Subscribes this reactive tracking scope to the ancestor Bloom<T?> node if found, or Bloom.constantNull if no matching provider exists.
- Returns the underlying value of type
T?.
Examples
@override
Widget build(BuildContext context, BloomVia via) {
final theme = via.maybeOf<AppTheme>(context);
return Text(theme?.name ?? 'Default');
}
Implementation
@pragma('vm:prefer-inline')
T? maybeOf<T>(BuildContext context) => this(context.maybeBloomOf<T>());