Skip to content

Instantly share code, notes, and snippets.

@sendbird-community
sendbird-community / pubspec.yaml
Last active May 27, 2021 15:40
Flutter | Sendbird + Dashchat Dependencies
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
sendbird_sdk: ^3.0.11
dash_chat: ^1.1.15
@sendbird-community
sendbird-community / sample.dart
Created April 23, 2021 15:36
Flutter | Import statement
import 'package:sendbird_sdk/sendbird_sdk.dart';
@sendbird-community
sendbird-community / sample.dart
Created April 23, 2021 15:37
Flutter | Init
final sendbird = SendbirdSdk(appId: "your_app_id");
@sendbird-community
sendbird-community / sample.dart
Last active April 23, 2021 15:38
Flutter | Connect user
final user = await sendbird.connect("unique_user_id");
@sendbird-community
sendbird-community / sample.dart
Created April 23, 2021 15:39
Flutter | Connect
Future<User> connect(String appId, String userId) async {
try {
final sendbird = SendbirdSdk(appId: appId);
final user = await sendbird.connect(userId);
return user;
} catch (e) {
print('connect: ERROR: $e');
throw e;
}
}
@sendbird-community
sendbird-community / sample.dart
Created April 23, 2021 18:45
Flutter | Get user channels
Future<List<GroupChannel>> getGroupChannels() async {
try {
final query = GroupChannelListQuery()
..includeEmptyChannel = true
..order = GroupChannelListOrder.latestLastMessage
..limit = 15;
return await query.loadNext();
} catch (e) {
print('getGroupChannels: ERROR: $e');
return [];
@sendbird-community
sendbird-community / sample.dart
Created April 23, 2021 18:51
Flutter | Create channel from user ids
Future<GroupChannel> createChannel(List<String> userIds) async {
try {
final params = GroupChannelParams()..userIds = userIds;
final channel = await GroupChannel.createChannel(params);
return channel;
} catch (e) {
print('createChannel: ERROR: $e');
throw e;
}
}
@sendbird-community
sendbird-community / sample.dart
Created April 27, 2021 23:20
Flutter | Init State with channelEventHandler setup
@override
void initState() {
super.initState();
SendbirdSdk().addChannelEventHandler('channel_list_view', this);
updateGroupChannels();
}
@override
void dispose() {
SendbirdSdk().removeChannelEventHandler("channel_list_view");
@sendbird-community
sendbird-community / sample.dart
Created April 27, 2021 23:44
Flutter | Connect Example
connect("sendbird_application_id", "unique_user_id").then((user) {
// Push next page or now call up channels to display
}).catchError((error) {
// Handle error
}
@sendbird-community
sendbird-community / sample.dart
Last active April 28, 2021 21:41
Flutter | Get application users
Future<List<User>> getUsers() async {
try {
final query = ApplicationUserListQuery();
List<User> users = await query.loadNext();
return users;
} catch (e) {
print('getUsers: ERROR: $e');
return [];
}
}