tbib_bloc_extensions 1.0.1
tbib_bloc_extensions: ^1.0.1 copied to clipboard
Use this extension to get your bloc and access it without context.
TBIB_Bloc_Extensions #
Use this extension to get your bloc and access it without context
Usage #
// Don't use BlocProvider() but use BlocProviderContext
BlocProviderContext(
create: (context) => YourBloc(),
child: child
);
- When need to get your bloc
// don't use BlocProvider.of<YourBloc>(context) use
BlocExt.getBloc<YourBloc>();
Come see how library work #
// widget BlocProviderContext
@override
Widget build(BuildContext context) {
return BlocProvider(
create: create,
child: Builder(builder: (context) {
BlocExt.setBlocContext = context; // see i get your context and send it to static variable
return child;
}),
);
}
BlocExt.getBloc<YourBloc>() // it use BlocProvider.of<T>(_blocContext)
- Thank You.