showNotification method
Implementation
Future<void> showNotification({
required String action,
required String title,
required String tag,
String? body,
String? imageUrl,
bool? requiresInteraction,
List<Map<String, String>>? actions,
}) async {
// request background permissions
if(!await hasPermission()) {
bool result = await requestPermission();
if(!result) {
printDebug("Cannot show notification with permission.");
return;
}
}
final notification = <String, dynamic>{
'action': action,
'payload': {
'title': title,
'options': {
'tag': tag,
'body': body,
'image': imageUrl,
// TODO(cybex-dev): Service worker events i.e. 'notificationclick' & 'notificationclose' are (on Windows) intercepted before reaching twilio-sw, thus do not respond to events.
'actions': actions,
// TODO(cybex-dev) Hide requires interaction until we can handle events in the service worker (see above)
'requireInteraction': requiresInteraction,
}
}
};
// See above, actions are removed temporarily on Windows notifications since they aren't triggered/received by Service Worker.
// if (kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
// notification['payload']['options']['actions'] = [];
// }
_twilioSW.send(notification);
}