blocState<R extends Bloc<S>> method

S? blocState<R extends Bloc<S>>()

Get the current Bloc.state from a Bloc that exists in an ancestor widget

returns null if none is found

Implementation

S? blocState<R extends Bloc<S>>() {
  final bloc = BlocProvider.of<R>(this);
  final hasState = bloc?.hasState ?? false;
  return hasState ? bloc!.state : null;
}