diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eeb3cc3..d8801e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.2 - 21/12/2024 +## Added +- Listen when scan ticket error + ## v0.1.1 - 18/12/2024 ## Added - Secure ticket's QR code diff --git a/lib/pages/ticket_details/ticket_details.dart b/lib/pages/ticket_details/ticket_details.dart index 68c1b222..50e582cd 100644 --- a/lib/pages/ticket_details/ticket_details.dart +++ b/lib/pages/ticket_details/ticket_details.dart @@ -67,6 +67,7 @@ class TicketDetailsController extends State _getTicketInfo(); _startQrTimer(); _listenRealtimeChanges(); + _listenBroadcastError(); loggy.info('TicketDetailsController initialized'); } @@ -92,6 +93,52 @@ class TicketDetailsController extends State .subscribe(); } + void _listenBroadcastError() { + final key = selectedTicketId ?? ticket?.id; + + if (key == null) { + return; + } + + final channelName = 'error_$key'; + + Supabase.instance.client + .channel( + channelName, + opts: RealtimeChannelConfig( + key: key, + ), + ) + .onBroadcast( + event: 'scan_ticket_error', + callback: _handleBroadcastError, + ) + .subscribe(); + } + + void _handleBroadcastError(Map payload) async { + loggy.info('Broadcast error: $payload'); + + await DialogUtils.show( + context: context, + title: 'Error', + description: + 'Error occurred while scanning the ticket.\n If you did not scan the ticket, please contact the parking lot staff.', + svgImage: ImagePaths.imgDialogError, + actions: (context) { + return [ + ActionButton( + type: ActionButtonType.positive, + label: 'OK', + onPressed: () { + DialogUtils.hide(context); + }, + ), + ]; + }, + ); + } + void _handleRealtimeChanges(PostgresChangePayload payload) { loggy.info('Realtime changes: $payload'); const table = TicketTable();