0

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.

Robert Sandberg
  • 6,832
  • 2
  • 12
  • 30
angelina
  • 59
  • 2
  • 11
  • how?can you pls eloborate . for example i want to have dropdown1-> dropdown2 -> list in the above heirarchy – angelina Jun 30 '22 at 08:49

1 Answers1

0

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

Sajjad
  • 2,593
  • 16
  • 26