tbib_bloc_extensions 2.0.5 copy "tbib_bloc_extensions: ^2.0.5" to clipboard
tbib_bloc_extensions: ^2.0.5 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

note v1.0.2 solve can't get bloc if bloc in runApp see how init package #

// 1- need to create navigation key 
  GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

 // 2 in material app or cupertino app
 MitXMaterialApp(
            navigatorKey: navigatorKey,
            ....
            builder: (context, child) {
              TBIBBlocExt.init(navigatorKey);
              ....
              return child!
            }
 );

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.
1
likes
145
points
76
downloads

Publisher

unverified uploader

Weekly Downloads

Use this extension to get your bloc and access it without context.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, flutter, flutter_bloc, provider

More

Packages that depend on tbib_bloc_extensions