Skip to content

Instantly share code, notes, and snippets.

@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
Created April 28, 2021 18:13
Flutter | Navigation bar with createChannels
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: navigationBar(),
body: body(context),
);
}
Widget navigationBar() {
return AppBar(
@sendbird-community
sendbird-community / channel_list_view.dart
Created April 28, 2021 18:24
Flutter | Initial channel list view
import 'package:flutter/material.dart';
import 'package:sendbird_sdk/sendbird_sdk.dart';
class ChannelListView extends StatefulWidget {
@override
_ChannelListViewState createState() => _ChannelListViewState();
}
class _ChannelListViewState extends State<ChannelListView>
with ChannelEventHandler {