You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

web3modal_flutter关闭底部弹窗时误退当前路由问题求助

问题描述

在Flutter项目中使用web3modal_flutter包打开钱包选择底部弹窗时,点击弹窗的关闭按钮(X),包会执行Navigator.pop(context)退出当前所在的页面路由,而非仅关闭底部弹窗。但在Dialog组件内调用相同的openModal方法时功能正常,使用同一个context调用自定义的bottom sheet也能正常关闭。目前怀疑是传入的context存在问题,但未排查到代码异常。

相关代码

页面实现代码

@RoutePage()
class CreateWalletQuickFundPage extends StatelessWidget {
  const CreateWalletQuickFundPage({super.key});

  @override
  Widget build(BuildContext context) {
    final userBloc = context.read<UserBloc>();

    return PageWrapper(
      cubit: ConnectWalletCubit(context.read<UserBloc>()),
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 32),
        child: Column(
          children: [
            const SizedBox(height: 32),
            BlocBuilder<UserBloc, UserState>(
              builder: (context, state) {
                return WalletQrCode(wallet: state.selectedWallet!);
              },
            ),
            const SizedBox(height: 32),
            Text(
              context.l10n.welcomeToYourNewWallet,
              style: context.typography.heading2,
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 14),
            ConstrainedBox(
              constraints: const BoxConstraints(maxWidth: 290),
              child: Text(
                context.l10n.thisIsYourPersonalBankVaultForTokens,
                style: context.typography.text14,
                textAlign: TextAlign.center,
              ),
            ),
            const SizedBox(height: 50),
            BlocBuilder<ConnectWalletCubit, ConnectWalletState>(
              builder: (context, state) {
                final connectWalletCubit = context.read<ConnectWalletCubit>();

                return Button(
                  onTap: () async {
                    await connectWalletCubit.w3mService.openModal(context);
                  },
                  text: context.l10n.fundYourWallet,
                  activeColor: context.colors.moonGreen,
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}

自定义Bottom Sheet调用代码

showBottomSheet(
    context: context,
    builder: (context) =>
    const SelectNetworkBottomSheet(),
);

内容的提问来源于stack exchange,提问作者Nixon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 11:46:21