@@ -63,7 +63,11 @@ class ChannelListCore extends StatefulWidget {
|
||||
required this.loadingBuilder,
|
||||
required this.listBuilder,
|
||||
this.filter,
|
||||
this.options,
|
||||
this.state = true,
|
||||
this.watch = true,
|
||||
this.presence = false,
|
||||
this.memberLimit,
|
||||
this.messageLimit,
|
||||
this.sort,
|
||||
this.pagination = const PaginationParams(
|
||||
limit: 25,
|
||||
@@ -94,11 +98,11 @@ class ChannelListCore extends StatefulWidget {
|
||||
/// You can also filter other built-in channel fields.
|
||||
final Filter? filter;
|
||||
|
||||
/// Query channels options.
|
||||
///
|
||||
/// state: if true returns the Channel state
|
||||
/// watch: if true listen to changes to this Channel in real time.
|
||||
final Map<String, dynamic>? options;
|
||||
// bool state = true,
|
||||
// bool watch = true,
|
||||
// bool presence = false,
|
||||
// int? memberLimit,
|
||||
// int? messageLimit,
|
||||
|
||||
/// The sorting used for the channels matching the filters.
|
||||
/// Sorting is based on field and direction, multiple sorting options can be
|
||||
@@ -107,6 +111,17 @@ class ChannelListCore extends StatefulWidget {
|
||||
/// _at or member_count. Direction can be ascending or descending.
|
||||
final List<SortOption<ChannelModel>>? sort;
|
||||
|
||||
/// If true returns the Channel state
|
||||
final bool state;
|
||||
|
||||
/// If true listen to changes to this Channel in real time.
|
||||
final bool watch;
|
||||
|
||||
final bool presence;
|
||||
|
||||
final int? memberLimit;
|
||||
final int? messageLimit;
|
||||
|
||||
/// Pagination parameters
|
||||
/// limit: the number of channels to return (max is 30)
|
||||
/// offset: the offset (max is 1000)
|
||||
@@ -149,18 +164,26 @@ class ChannelListCoreState extends State<ChannelListCore> {
|
||||
Future<void> loadData() => _channelsBloc.queryChannels(
|
||||
filter: widget.filter,
|
||||
sortOptions: widget.sort,
|
||||
state: widget.state,
|
||||
watch: widget.watch,
|
||||
presence: widget.presence,
|
||||
memberLimit: widget.memberLimit,
|
||||
messageLimit: widget.messageLimit,
|
||||
paginationParams: widget.pagination,
|
||||
options: widget.options,
|
||||
);
|
||||
|
||||
/// Fetches more channels with updated pagination and updates the widget
|
||||
Future<void> paginateData() => _channelsBloc.queryChannels(
|
||||
filter: widget.filter,
|
||||
sortOptions: widget.sort,
|
||||
state: widget.state,
|
||||
watch: widget.watch,
|
||||
presence: widget.presence,
|
||||
memberLimit: widget.memberLimit,
|
||||
messageLimit: widget.messageLimit,
|
||||
paginationParams: widget.pagination.copyWith(
|
||||
offset: _channelsBloc.channels?.length ?? 0,
|
||||
),
|
||||
options: widget.options,
|
||||
);
|
||||
|
||||
StreamSubscription<Event>? _subscription;
|
||||
@@ -200,7 +223,11 @@ class ChannelListCoreState extends State<ChannelListCore> {
|
||||
|
||||
if (widget.filter?.toString() != oldWidget.filter?.toString() ||
|
||||
jsonEncode(widget.sort) != jsonEncode(oldWidget.sort) ||
|
||||
widget.options?.toString() != oldWidget.options?.toString() ||
|
||||
widget.state != oldWidget.state ||
|
||||
widget.watch != oldWidget.watch ||
|
||||
widget.presence != oldWidget.presence ||
|
||||
widget.messageLimit != oldWidget.messageLimit ||
|
||||
widget.memberLimit != oldWidget.memberLimit ||
|
||||
widget.pagination.toJson().toString() !=
|
||||
oldWidget.pagination.toJson().toString()) {
|
||||
loadData();
|
||||
|
||||
@@ -95,8 +95,13 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
||||
Future<void> queryChannels({
|
||||
Filter? filter,
|
||||
List<SortOption<ChannelModel>>? sortOptions,
|
||||
bool state = true,
|
||||
bool watch = true,
|
||||
bool presence = false,
|
||||
int? memberLimit,
|
||||
int? messageLimit,
|
||||
bool waitForConnect = true,
|
||||
PaginationParams paginationParams = const PaginationParams(limit: 30),
|
||||
Map<String, dynamic>? options,
|
||||
}) async {
|
||||
final client = _streamChatCoreState!.client;
|
||||
|
||||
@@ -117,7 +122,12 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
||||
await for (final channels in client.queryChannels(
|
||||
filter: filter,
|
||||
sort: sortOptions,
|
||||
options: options,
|
||||
state: state,
|
||||
watch: watch,
|
||||
presence: presence,
|
||||
memberLimit: memberLimit,
|
||||
messageLimit: messageLimit,
|
||||
waitForConnect: waitForConnect,
|
||||
paginationParams: paginationParams,
|
||||
)) {
|
||||
newChannels = channels;
|
||||
|
||||
@@ -109,7 +109,7 @@ class StreamChatCoreState extends State<StreamChatCore>
|
||||
if (user != null) {
|
||||
if (state == AppLifecycleState.paused) {
|
||||
if (widget.onBackgroundEventReceived == null) {
|
||||
client.disconnect();
|
||||
client.closeConnection();
|
||||
return;
|
||||
}
|
||||
_eventSubscription = client.on().listen(
|
||||
@@ -118,7 +118,7 @@ class StreamChatCoreState extends State<StreamChatCore>
|
||||
|
||||
void onTimerComplete() {
|
||||
_eventSubscription?.cancel();
|
||||
client.disconnect();
|
||||
client.closeConnection();
|
||||
}
|
||||
|
||||
_disconnectTimer = Timer(widget.backgroundKeepAlive, onTimerComplete);
|
||||
@@ -128,7 +128,7 @@ class StreamChatCoreState extends State<StreamChatCore>
|
||||
_disconnectTimer?.cancel();
|
||||
} else {
|
||||
if (client.wsConnectionStatus == ConnectionStatus.disconnected) {
|
||||
client.connect();
|
||||
client.openConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ class UserListCore extends StatefulWidget {
|
||||
required this.listBuilder,
|
||||
Key? key,
|
||||
this.filter,
|
||||
this.options,
|
||||
this.sort,
|
||||
this.presence,
|
||||
this.pagination,
|
||||
this.groupAlphabetically = false,
|
||||
this.userListController,
|
||||
@@ -92,18 +92,15 @@ class UserListCore extends StatefulWidget {
|
||||
/// You can also filter other built-in channel fields.
|
||||
final Filter? filter;
|
||||
|
||||
/// Query channels options.
|
||||
///
|
||||
/// state: if true returns the Channel state
|
||||
/// watch: if true listen to changes to this Channel in real time.
|
||||
final Map<String, dynamic>? options;
|
||||
|
||||
/// The sorting used for the channels matching the filters.
|
||||
/// Sorting is based on field and direction, multiple sorting options can be
|
||||
/// provided. You can sort based on last_updated, last_message_at, updated_at,
|
||||
/// created_at or member_count. Direction can be ascending or descending.
|
||||
final List<SortOption>? sort;
|
||||
|
||||
///
|
||||
final bool? presence;
|
||||
|
||||
/// Pagination parameters
|
||||
/// limit: the number of users to return (max is 30)
|
||||
/// offset: the offset (max is 1000)
|
||||
@@ -186,22 +183,22 @@ class UserListCoreState extends State<UserListCore>
|
||||
},
|
||||
);
|
||||
|
||||
// ignore: public_member_api_docs
|
||||
/// Fetches initial users and updates the widget
|
||||
Future<void> loadData() => _usersBloc!.queryUsers(
|
||||
filter: widget.filter,
|
||||
sort: widget.sort,
|
||||
presence: widget.presence,
|
||||
pagination: widget.pagination,
|
||||
options: widget.options,
|
||||
);
|
||||
|
||||
// ignore: public_member_api_docs
|
||||
/// Fetches more users with updated pagination and updates the widget
|
||||
Future<void> paginateData() => _usersBloc!.queryUsers(
|
||||
filter: widget.filter,
|
||||
sort: widget.sort,
|
||||
presence: widget.presence,
|
||||
pagination: widget.pagination!.copyWith(
|
||||
offset: _usersBloc!.users?.length ?? 0,
|
||||
),
|
||||
options: widget.options,
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -209,7 +206,7 @@ class UserListCoreState extends State<UserListCore>
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.filter?.toString() != oldWidget.filter?.toString() ||
|
||||
jsonEncode(widget.sort) != jsonEncode(oldWidget.sort) ||
|
||||
widget.options?.toString() != oldWidget.options?.toString() ||
|
||||
widget.presence != oldWidget.presence ||
|
||||
widget.pagination?.toJson().toString() !=
|
||||
oldWidget.pagination?.toJson().toString()) {
|
||||
loadData();
|
||||
|
||||
@@ -63,7 +63,7 @@ class UsersBlocState extends State<UsersBloc>
|
||||
Future<void> queryUsers({
|
||||
Filter? filter,
|
||||
List<SortOption>? sort,
|
||||
Map<String, dynamic>? options,
|
||||
bool? presence,
|
||||
PaginationParams? pagination,
|
||||
}) async {
|
||||
final client = _streamChatCore.client;
|
||||
@@ -82,7 +82,7 @@ class UsersBlocState extends State<UsersBloc>
|
||||
final usersResponse = await client.queryUsers(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
options: options,
|
||||
presence: presence,
|
||||
pagination: pagination,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user