Skip to main content

Pin a channel

Pin channels to the top of the channel list using the pin / unpin methods on BaseChannel instances. The pinned state is reflected in the isPinned property.

Pin a channel

Pin a channel to the top of the list. The pinned state syncs to the server and persists across devices. This is a BaseChannel instance method.

Method

Dart
Future<int> pin(PinParams params, ErrorHandler handler);

Parameters

ParameterTypeDescription
paramsPinParamsPin parameters
handlerErrorHandlerResult callback

PinParams properties

PropertyTypeDescription
updateOperationTimeboolWhether to update the channel's operation timestamp

Code example

Dart
BaseChannel channel = ...;

int? ret = await channel.pin(
PinParams(updateOperationTime: true),
(NCError? error) {
if (error?.isSuccess == true) {
print('Channel pinned');
}
},
);

Unpin a channel

Method

Dart
Future<int> unpin(ErrorHandler handler);

Code example

Dart
int? ret = await channel.unpin((NCError? error) {
if (error?.isSuccess == true) {
print('Channel unpinned');
}
});

Get pinned channels

Method

Dart
static Future<int> getPinnedChannels(List<ChannelType> types, OperationHandler<List<BaseChannel>> handler);

Code example

Dart
final types = [ChannelType.direct, ChannelType.group];

int? ret = await BaseChannel.getPinnedChannels(types, (List<BaseChannel>? channels, NCError? error) {
if (error == null) {
print('Pinned channels: ${channels?.length}');
}
});

Listen for pin state sync

The SDK syncs pin state changes across devices. Register a ChannelHandler to receive real-time notifications.

Register listener

Dart
NCEngine.addChannelHandler(
'my_pin_listener',
ChannelHandler(
onChannelPinnedSync: (event) {
print(
'Channel ${event.channelIdentifier.channelId} pin state changed: ${event.isPinned}',
);
},
),
);

Remove listener

Dart
NCEngine.removeChannelHandler('my_pin_listener');