I want to suggest idiomatic useful functions :)
T getBloc<T extends Cubit<Object>>(BuildContext context) =>
BlocProvider.of<T>(context);
T getRepository<T>(BuildContext context) => RepositoryProvider.of<T>(context);
usage:
getBloc<LoginCubit>(context).logInWithCredentials();
// ...
SignUpCubit(getRepository<AuthenticationRepository>(context));
Hi @comerc 👋
Thanks for the suggestions! There are already existing extension methods on BuildContext for this.
You can use context.read<LoginCubit>() or context.read<AuthenticationRepository>().
Hope that helps! ✌
Most helpful comment
Hi @comerc 👋
Thanks for the suggestions! There are already existing extension methods on
BuildContextfor this.You can use
context.read<LoginCubit>()orcontext.read<AuthenticationRepository>().Hope that helps! ✌