angelina
angelina

Reputation: 109

Flutter multi bloc provider using cubit

I have a screen where there is a list populating items, now I want to add dropdown list above the list, so I am confused on how to implement it.

Following is a code snippet:

body: BlocProvider(
        create: (_) => HomeCubit()..fetchUsers(),
        child: BlocBuilder<HomeCubit, HomeState>(
          builder: (context, state) {
            switch (state.status) {
              case HomeStatus.failure:
                return const Center(child: Text('failed to fetch topics'));
              case HomeStatus.success:
                // if (state.topics.isEmpty) {
                //   return const Center(child: Text('no users'));
                // }
                return _buildUserList(state);
              default:
                return Center(child: CircularProgressIndicator(color: Theme.of(context).primaryColor));
            }
          },
        ),
      ),
    );

I want to know how I can call HomeCubit()..getdropdownitems() items method so that I can display a dropdown just above the fetchusers list.

Upvotes: 0

Views: 1668

Answers (1)

Sajjad
Sajjad

Reputation: 3228

you want to call a function in your HomeCubit :

it's accessible with

context.read<HomeCubit>().myfunction()

but pay attention to your context it should has a parent of bloc provider with HomeCubit

Upvotes: 1

Related Questions