Bloc: getBloc() & getRepository()

Created on 30 Nov 2020  Â·  1Comment  Â·  Source: felangel/bloc

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));
question waiting for response

Most helpful comment

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! ✌

>All comments

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! ✌

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krusek picture krusek  Â·  3Comments

tigranhov picture tigranhov  Â·  3Comments

clicksocial picture clicksocial  Â·  3Comments

timtraversy picture timtraversy  Â·  3Comments

craiglabenz picture craiglabenz  Â·  3Comments