Skip to content

Commit

Permalink
Handle broadcast error
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui committed Dec 21, 2024
1 parent 05de4c4 commit 3c3643f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/pages/ticket_details/ticket_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TicketDetailsController extends State<TicketDetails>
_getTicketInfo();
_startQrTimer();
_listenRealtimeChanges();
_listenBroadcastError();
loggy.info('TicketDetailsController initialized');
}

Expand All @@ -92,6 +93,52 @@ class TicketDetailsController extends State<TicketDetails>
.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<String, dynamic> 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 <Widget>[
ActionButton(
type: ActionButtonType.positive,
label: 'OK',
onPressed: () {
DialogUtils.hide(context);
},
),
];
},
);
}

void _handleRealtimeChanges(PostgresChangePayload payload) {
loggy.info('Realtime changes: $payload');
const table = TicketTable();
Expand Down

0 comments on commit 3c3643f

Please sign in to comment.