import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:siro_driver/controller/notification/notification_captain_controller.dart'; import '../widgets/ui/siro_ui.dart'; class NotificationCaptain extends StatelessWidget { const NotificationCaptain({super.key}); @override Widget build(BuildContext context) { Get.put(NotificationCaptainController()); return SiroPage( title: 'Notifications'.tr, body: GetBuilder( builder: (controller) { if (controller.isLoading) return const SiroLoading(); final data = controller.notificationData['message']; // الردّ قد يكون نصاً ("No notification data found") لا قائمة. // كان الكود يقرأ `.length` عليه ثم يفتح حواراً من داخل `itemBuilder` // — أي أثناء البناء، وهو ما يرمي استثناءً بدل عرض حالة فراغ. final List items = data is List ? data : const []; if (items.isEmpty) { return SiroEmptyState( icon: Icons.notifications_off_rounded, title: 'No Notifications'.tr, message: 'There are no notifications at this time.'.tr, ); } return ListView.builder( padding: SiroUi.pageInsets, itemCount: items.length, itemBuilder: (BuildContext context, int index) { final res = items[index]; return SiroCard( onTap: () => _showDetails( context, res['title']?.toString() ?? '', res['body']?.toString() ?? '', () { controller.updateNotification(res['id'].toString()); Navigator.of(context).pop(); }, ), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ SiroIconBadge(Icons.notifications_rounded, color: SiroUi.interactive(context)), const SizedBox(width: 12), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( res['title']?.toString() ?? '', style: Theme.of(context) .textTheme .bodyMedium ?.copyWith(fontWeight: FontWeight.bold), ), const SizedBox(height: 4), Text( res['body']?.toString() ?? '', maxLines: 3, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.bodySmall, ), ], ), ), ], ), ); }, ); }, ), ); } void _showDetails(BuildContext context, String title, String content, VoidCallback onConfirm) { showDialog( context: context, builder: (BuildContext ctx) => AlertDialog( icon: SiroIconBadge(Icons.notifications_active_rounded, color: SiroUi.interactive(ctx), size: 22), title: Text(title, textAlign: TextAlign.center), content: Text(content, textAlign: TextAlign.center), actionsAlignment: MainAxisAlignment.center, actions: [ TextButton( onPressed: () => Navigator.of(ctx).pop(), child: Text('Back'.tr, style: TextStyle(color: SiroUi.subtle(ctx))), ), ElevatedButton( onPressed: onConfirm, child: Text('OK'.tr), ), ], ), ); } }