Flutter:检查模态底部 sheet 是否通过向下拖动或 Navigator.pop 关闭
Flutter: check the modal bottom sheet is closed by drag down or by Navigator.pop
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
检查模态底部 sheet 是否关闭吗?
因为我有一个条件,当modal被Navigator.pop
关闭时,想执行API功能(_getSavingsPlanDetail
),但是如果通过向下拖动就不行了。
因为现在 _getSavingsPlanDetail
总是被执行。
要创建模态底部 sheet,我使用这个包:https://pub.dev/packages/modal_bottom_sheet
你可以这样试试
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);
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
检查模态底部 sheet 是否关闭吗?
因为我有一个条件,当modal被Navigator.pop
关闭时,想执行API功能(_getSavingsPlanDetail
),但是如果通过向下拖动就不行了。
因为现在 _getSavingsPlanDetail
总是被执行。
要创建模态底部 sheet,我使用这个包:https://pub.dev/packages/modal_bottom_sheet
你可以这样试试
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 ofNavigator.pop(context);