showLoading static method
void
showLoading({})
Implementation
static void showLoading({
String? text = "加载中...",
Color backgroundColor = Colors.black54,
Color indicatorColor = Colors.white,
double indicatorSize = 40.0,
}) {
// 关闭可能存在的旧弹窗
if (Get.isDialogOpen ?? false) {
Get.back();
}
// 显示新的 Loading 弹窗
Get.dialog(
barrierDismissible: false, // 禁止点击空白处关闭
PopScope(
// 禁止物理返回键关闭(关键替换:用 PopScope 替代 WillPopScope)
canPop: false, // 控制是否允许返回
child: Material(
color: Colors.transparent,
child: Stack(
children: [
Center(
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 16,
),
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(8),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 圆形进度指示器
SizedBox(
width: indicatorSize,
height: indicatorSize,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(indicatorColor),
strokeWidth: 3,
),
),
// 提示文本
if (text != null && text.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text(
text,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
),
),
],
),
),
),
],
),
),
),
);
}