Flutter Getx问题:调用Get.snackbar()后无法返回页面
解决GetX Snackbar显示时无法返回页面的问题
- 问题原因:Get.snackbar默认将
*blockBackgroundInteraction*参数设为true,这会拦截背景页面的所有交互操作(包括返回按钮事件),必须等Snackbar消失后才能恢复。 - 解决办法:在调用Get.snackbar时显式设置
blockBackgroundInteraction: false,允许Snackbar显示期间背景页面正常响应交互。
修改后的完整代码:
SnackbarController snackbar({ required String title, required String message, Color? bgColor, Color? textColor, }) { return Get.snackbar( title, message, snackPosition: SnackPosition.TOP, backgroundColor: bgColor ?? Colors.green, colorText: textColor ?? Apc.white, isDismissible: true, dismissDirection: DismissDirection.horizontal, // 允许背景页面交互,包括返回操作 blockBackgroundInteraction: false, ); }
添加该参数后,用户在Snackbar显示时既能正常触发页面返回,也能保留Snackbar本身的滑动关闭功能,同时背景页面的其他可交互元素也能正常响应操作。
内容的提问来源于stack exchange,提问作者Jostin Akkara
相关产品推荐
相关产品推荐

