如何在颤动中的两个小部件之间伸展上下文?

发布于 2025-02-02 21:07:50 字数 3078 浏览 2 评论 0原文

我有两个不同的小部件。我在另一个中间使用的第二个小部件。问题是我不了解如何将上下文扩展到下一个小部件。 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()拨打不包含底部表格的上下文。

因此,我想利用建筑物发生的前一个小部件的上下文。有人知道该怎么做吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文