Update: 2026-08-08 16:55:39
This commit is contained in:
@@ -1,84 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_driver/controller/notification/notification_captain_controller.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../widgets/ui/siro_ui.dart';
|
||||
|
||||
class NotificationCaptain extends StatelessWidget {
|
||||
const NotificationCaptain({Key? key}) : super(key: key);
|
||||
const NotificationCaptain({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(NotificationCaptainController());
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text('Notifications'.tr),
|
||||
leading: CupertinoNavigationBarBackButton(
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: GetBuilder<NotificationCaptainController>(
|
||||
builder: (notificationCaptainController) =>
|
||||
notificationCaptainController.isLoading
|
||||
? const Center(child: CupertinoActivityIndicator())
|
||||
: ListView.builder(
|
||||
itemCount: notificationCaptainController
|
||||
.notificationData['message'].length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (notificationCaptainController
|
||||
.notificationData['message'] ==
|
||||
"No notification data found") {
|
||||
_showCupertinoDialog(context, 'No Notifications',
|
||||
'There are no notifications at this time.');
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
var res = notificationCaptainController
|
||||
.notificationData['message'][index];
|
||||
return CupertinoListTile(
|
||||
leading: const Icon(CupertinoIcons.bell_fill),
|
||||
title: Text(
|
||||
res['title'],
|
||||
style:
|
||||
CupertinoTheme.of(context).textTheme.textStyle,
|
||||
),
|
||||
subtitle: Text(
|
||||
res['body'],
|
||||
style: CupertinoTheme.of(context)
|
||||
return SiroPage(
|
||||
title: 'Notifications'.tr,
|
||||
body: GetBuilder<NotificationCaptainController>(
|
||||
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
|
||||
.tabLabelTextStyle,
|
||||
.bodyMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
onTap: () {
|
||||
_showCupertinoDialog(
|
||||
context,
|
||||
res['title'],
|
||||
res['body'],
|
||||
onConfirm: () {
|
||||
notificationCaptainController
|
||||
.updateNotification(res['id'].toString());
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
res['body']?.toString() ?? '',
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showCupertinoDialog(BuildContext context, String title, String content,
|
||||
{VoidCallback? onConfirm}) {
|
||||
showCupertinoDialog(
|
||||
void _showDetails(BuildContext context, String title, String content,
|
||||
VoidCallback onConfirm) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => CupertinoAlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(content),
|
||||
actions: <CupertinoDialogAction>[
|
||||
CupertinoDialogAction(
|
||||
child: const Text('OK'),
|
||||
onPressed: onConfirm ?? () => Navigator.of(context).pop(),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user