import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; /// ============================================================ /// 【ReciteLoading】模态 loading —— 对标 uni.showLoading({mask:true}) /// /// 用于「切换中...」「正在提交」「加载中...」: /// ReciteLoading.show(context, '切换中...'); /// ...await... /// if (mounted) ReciteLoading.hide(context); /// /// 用根 Navigator 弹出,可盖在底部 tabbar 之上;barrier 拦截所有点击。 /// ============================================================ class ReciteLoading { ReciteLoading._(); static void show(BuildContext context, String text) { showDialog( context: context, barrierDismissible: false, useRootNavigator: true, builder: (_) => _ReciteLoadingView(text: text), ); } static void hide(BuildContext context) { final nav = Navigator.of(context, rootNavigator: true); if (nav.canPop()) nav.pop(); } } class _ReciteLoadingView extends StatelessWidget { const _ReciteLoadingView({required this.text}); final String text; @override Widget build(BuildContext context) { return Center( child: Container( padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 20.h), decoration: BoxDecoration( color: Colors.black.withValues(alpha: 0.75), borderRadius: BorderRadius.circular(12.r), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ const SizedBox( width: 24, height: 24, child: CircularProgressIndicator( strokeWidth: 2.5, valueColor: AlwaysStoppedAnimation(Colors.white), ), ), SizedBox(height: 12.h), Text( text, style: TextStyle( fontSize: 14.sp, color: Colors.white, decoration: TextDecoration.none, ), ), ], ), ), ); } }