loading static method
Show Loading Dialog while performing a task
Implementation
static Future<void> loading(
BuildContext context,
Future<void> Function() task,
) async {
// عرض نافذة الانتظار مع منع زر الرجوع
showDialog(
context: context,
barrierDismissible: false,
barrierColor: Colors.black87,
builder: (context) => PopScope(
canPop: false, // منع الرجوع
child: AlertDialog(
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.zero,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
content: Column(
// mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(color: Colors.white),
),
SizedBox(height: 16),
Text(
'...جاري التنفيذ',
style: TextStyle(color: Colors.white),
),
],
),
),
Image.asset(
'assets/images/almuhasib_color.png',
width: 70,
height: 70,
),
],
),
),
),
);
// تنفيذ العملية
await task();
// إغلاق النافذة بعد الانتهاء
if (!context.mounted) return;
Navigator.of(context).pop();
}