buildNotificationBubbleWidget static method
Widget?
buildNotificationBubbleWidget({
- required NotificationMessage message,
- required dynamic onError(
- NotificationWidgetError error
- dynamic onClick(
- NotificationMessage message,
- NotificationView view,
- NotificationAction action
- NotificationThemeMode themeMode = NotificationThemeMode.light,
Builds the notification bubble widget for a notification message
sent on Sendbird Dashboard.
themeMode
is only applied when the theme colors setting is Use both light and dark themes
on Sendbird Dashboard.
Implementation
static Widget? buildNotificationBubbleWidget({
required NotificationMessage message,
required Function(NotificationWidgetError error) onError,
Function(
NotificationMessage message,
NotificationView view,
NotificationAction action,
)?
onClick,
NotificationThemeMode themeMode = NotificationThemeMode.light,
}) {
if (message.notificationData == null) {
onError(NotificationWidgetError.notificationDataNotFoundError);
return null;
}
if (_instance._isNotificationInfoCached == false) {
onError(NotificationWidgetError.cacheNotFoundError);
return null;
}
if (_instance._isNotificationEnabled == false) {
onError(NotificationWidgetError.notificationDisabledError);
return null;
}
Widget? widget;
try {
final cachedSettings = _instance._cacheManager.cachedSettings;
if (cachedSettings.isNotEmpty) {
final settings = SbSettings.fromJson(cachedSettings);
if (settings.themeMode == 'light') {
themeMode = NotificationThemeMode.light;
} else if (settings.themeMode == 'dark') {
themeMode = NotificationThemeMode.dark;
}
final cachedTemplates = _instance._cacheManager.cachedTemplates;
final cachedTemplate =
cachedTemplates[message.notificationData!.templateKey];
if (cachedTemplate != null &&
(cachedTemplate as Map<String, dynamic>).isNotEmpty) {
// debugPrint(
// '[SendbirdChatWidget][buildNotificationBubbleWidget()][cache()][template]'
// ' key: ${message.notificationData!.templateKey}\n'
// '${const JsonEncoder.withIndent(' ').convert(cachedTemplate)}');
final template = SbTemplate.fromJson(cachedTemplate);
// debugPrint(
// '[SendbirdChatWidget][buildNotificationBubbleWidget()][templateVariables]\n'
// '${const JsonEncoder.withIndent(' ').convert(message.notificationData!.templateVariables)}');
widget = _instance._widgetManager.buildNotificationBubbleWidget(
message: message,
themeMode: themeMode,
settings: settings,
template: template,
notificationData: message.notificationData!,
onClick: onClick,
);
} else {
onError(NotificationWidgetError.templateNotFoundError);
return null;
}
} else {
onError(NotificationWidgetError.cacheNotFoundError);
return null;
}
} catch (e) {
debugPrint(
'[SendbirdChatWidget][buildNotificationBubbleWidget()][e] ${e.toString()}');
onError(NotificationWidgetError.unknownError);
return null;
}
return widget;
}