Flutter:通过向下拖动或 Navigator.pop 检查模态底部工作表是否已关闭

发布于 2025-01-13 01:25:59 字数 1267 浏览 0 评论 0原文

showCupertinoModalBottomSheet(
      expand: true,
      context: context,
      backgroundColor: ColorPalettes.white,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(10),
          topRight: Radius.circular(10),
        ),
      ),
      isDismissible: true,
      builder: (rootContext) => ManageSavingsPlanSheet(
        argument: ManageSelectArgument(
          iban: widget.argument.iban,
          cashBalance: widget.argument.cashBalance,
          digitalDepotAccountId: widget.argument.digitalDepotAccountId,
          withdrawBalance: widget.argument.withdrawBalance,
          canWithdraw: widget.argument.canWithdraw,
          isPaused: widget.argument.isPaused,
        ),
      ),
    ).then((_) => _getSavingsPlanDetail(context));

我们可以通过向下拖动或通过 Navigator.pop 检查模式底部表单是否关闭?

因为我有一个条件,当模态被 Navigator.pop 关闭时想要执行 API 函数 (_getSavingsPlanDetail),但如果通过向下拖动则不会。

因为目前 _getSavingsPlanDetail 始终执行。

要创建模态底部表,我使用此包: https://pub.dev/packages/modal_bottom_sheet

showCupertinoModalBottomSheet(
      expand: true,
      context: context,
      backgroundColor: ColorPalettes.white,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(10),
          topRight: Radius.circular(10),
        ),
      ),
      isDismissible: true,
      builder: (rootContext) => ManageSavingsPlanSheet(
        argument: ManageSelectArgument(
          iban: widget.argument.iban,
          cashBalance: widget.argument.cashBalance,
          digitalDepotAccountId: widget.argument.digitalDepotAccountId,
          withdrawBalance: widget.argument.withdrawBalance,
          canWithdraw: widget.argument.canWithdraw,
          isPaused: widget.argument.isPaused,
        ),
      ),
    ).then((_) => _getSavingsPlanDetail(context));

Can we check the modal bottom sheet is closed by drag down or by Navigator.pop?

Because I have a condition when the modal is closed by Navigator.pop want to execute API function (_getSavingsPlanDetail), but if by drag down is not.

Because for now the _getSavingsPlanDetail is always executed.

To create a modal bottom sheet, I use this package: https://pub.dev/packages/modal_bottom_sheet

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2025-01-20 01:25:59

你可以这样尝试

bool? b = await showCupertinoModalBottomSheet<bool?>(
      expand: true,
      context: context,
      backgroundColor: ColorPalettes.white,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(10),
          topRight: Radius.circular(10),
        ),
      ),
      isDismissible: true,
      builder: (rootContext) => ManageSavingsPlanSheet(
        argument: ManageSelectArgument(
          iban: widget.argument.iban,
          cashBalance: widget.argument.cashBalance,
          digitalDepotAccountId: widget.argument.digitalDepotAccountId,
          withdrawBalance: widget.argument.withdrawBalance,
          canWithdraw: widget.argument.canWithdraw,
          isPaused: widget.argument.isPaused,
        ),
      ),
    );

if(b == true){
// came from Navigator.pop
// can do anything
_getSavingsPlanDetail(context));
}else{
 // came from other way
}

注意:在 Navigator.pop(context); 的状态下使用 Navigator.pop(context, true);

you can try in this way

bool? b = await showCupertinoModalBottomSheet<bool?>(
      expand: true,
      context: context,
      backgroundColor: ColorPalettes.white,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(10),
          topRight: Radius.circular(10),
        ),
      ),
      isDismissible: true,
      builder: (rootContext) => ManageSavingsPlanSheet(
        argument: ManageSelectArgument(
          iban: widget.argument.iban,
          cashBalance: widget.argument.cashBalance,
          digitalDepotAccountId: widget.argument.digitalDepotAccountId,
          withdrawBalance: widget.argument.withdrawBalance,
          canWithdraw: widget.argument.canWithdraw,
          isPaused: widget.argument.isPaused,
        ),
      ),
    );

if(b == true){
// came from Navigator.pop
// can do anything
_getSavingsPlanDetail(context));
}else{
 // came from other way
}

Note: use Navigator.pop(context, true); instate of Navigator.pop(context);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文