sendbird_chat_widget 1.0.4 copy "sendbird_chat_widget: ^1.0.4" to clipboard
sendbird_chat_widget: ^1.0.4 copied to clipboard

With Sendbird Chat Widget for Flutter, you can easily build the widgets regarding the sendbird chat.

example/lib/main.dart

import 'package:sendbird_chat_sdk/sendbird_chat_sdk.dart';
import 'package:sendbird_chat_widget/sendbird_chat_widget.dart';

void main() async {
  // 1. Cache the notification settings and templates after authenticated
  await SendbirdChat.authenticateFeed('USER_ID', accessToken: 'SESSION_TOKEN');
  await SendbirdChatWidget.cacheNotificationInfo();

  // 2. Build a notification bubble widget in your chat view for notifications
  final message =
      NotificationMessage.fromJson({}); // Temporary code for compile

  final notificationBubbleWidget =
      SendbirdChatWidget.buildNotificationBubbleWidget(
    // This value must be a message in messageList in NotificationCollection.
    message: message,
    onClick: (message, view, action) {
      // Handle click event with action.type and action.data
    },
    themeMode: NotificationThemeMode.light, // or dark
    onError: (NotificationWidgetError error) {
      switch (error) {
        case NotificationWidgetError.notificationDisabledError:
          break;
        case NotificationWidgetError.cacheNotFoundError:
          SendbirdChatWidget.cacheNotificationInfo().then((result) {
            if (result) {
              // Refresh this notification bubble widget
            }
          });
          break;
        case NotificationWidgetError.templateNotFoundError:
          SendbirdChatWidget.getNotificationTemplate(
            key: message.notificationData!.templateKey,
          ).then((template) {
            if (template != null) {
              // Refresh this notification bubble widget
            }
          });
          break;
        case NotificationWidgetError.notificationDataNotFoundError:
          break;
        case NotificationWidgetError.unknownError:
          break;
      }
    },
  );

  if (notificationBubbleWidget == null) {
    // The onError() was invoked before.
  }

  // 3. Clear the cache after logout
  await SendbirdChat.disconnect();
  await SendbirdChatWidget.clearCachedNotificationInfo();
}
1
likes
120
pub points
81%
popularity

Publisher

verified publishersendbird.com

With Sendbird Chat Widget for Flutter, you can easily build the widgets regarding the sendbird chat.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

unknown (LICENSE)

Dependencies

flutter, json_annotation, sendbird_chat_sdk, shared_preferences

More

Packages that depend on sendbird_chat_widget