0

I have two different widget. The second widget I use in the middle of the other. The problem is that I don't understand how to extend the context to the next widget. fіrst widget:

 Widget _getRow({
    required String name,
    required String fullAddress,
    required String id,
    required ValueChanged<String> onTap,
  }) {
    return Material(
      color: Colorz.white,
      child: InkWell(

        splashColor: Colorz.selectedListItemBG2,
        child: BlocBuilder<AddressesBloc, AddressesState>(
            buildWhen: (previous, current) =>
                current is AddressesRemoveItemState,
            builder: (context, state) {
              bool progress;
              if (state is AddressesRemoveItemState && id == state.addressId) {
                progress = state.isProgress;
              } else {
                progress = false;
              }
              return Stack(
                children: [
                  progress
                      ? Center(
                          child: Container(
                              color: Colorz.transparent30,
                              child: const PlatformProgressIndicator()),
                        )
                      : const EmptyWidget(),
                  _listItemColumn(
                    name: name,
                    fullAddress: fullAddress,
                    id: id
                  )
                ],
              );
            }),
        onTap: () {},
      ),
    );
  }

second widget:

  _listItemColumn({
    required String name,
    required String fullAddress,
    required String id,
  }) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.fromLTRB(
              Margins.medium, Margins.tiny, Margins.tiny, Margins.small),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: [
              ),
              Material(
                color: Colorz.white,
                child: InkWrapper(
                  splashColor: Colorz.lighterGray,
                  child: IconButton(
                    alignment: Alignment.center,
                    icon: SvgPicture.asset(
                      Img.listItemMenu,
                    ),
                    onPressed: () {
                      /*nan*/
                    },
                  ),
                  onTap: () {
                    BlocProvider.of<BottomSheetBloc>(context).add(
                       BottomSheetEventOpenRemoveAddress(
                        addressId: id ,
                      ),);
                  },
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

When I use BlocProvider:

BlocProvider.of<BottomSheetBloc>(context).add(
                   BottomSheetEventOpenRemoveAddress(
                    addressId: id ,
                  ),);

I have an error:

BlocProvider.of() called with a context that does not contain a BottomSheetBloc.

So I want to use the context of the previous widget where the building takes place. Does anyone know how to do this?

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Andrii Havrylyak
  • 675
  • 6
  • 16

0 Answers0