From 6427e34119f8a26952a814e841191a498d997cf6 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 15 Sep 2021 20:50:44 +0530 Subject: [PATCH 1/3] feat(ui, core): deprecate `pagination` in favor of `limit` Signed-off-by: xsahil03x --- .../lib/src/channel_list_view.dart | 25 +++++++++---- .../lib/src/message_search_list_view.dart | 23 +++++++++--- .../lib/src/user_list_view.dart | 21 ++++++++--- .../theme/channel_list_view_theme_test.dart | 2 +- .../src/theme/user_list_view_theme_test.dart | 4 +-- .../lib/src/channel_list_core.dart | 30 +++++++++++----- .../lib/src/message_search_list_core.dart | 36 ++++++++++++++----- .../lib/src/user_list_core.dart | 28 +++++++++++---- .../test/channel_list_core_test.dart | 14 ++++++++ .../test/message_search_list_core_test.dart | 15 ++++++++ .../test/user_list_core_test.dart | 13 +++++++ 11 files changed, 167 insertions(+), 44 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/channel_list_view.dart b/packages/stream_chat_flutter/lib/src/channel_list_view.dart index 35fc6d73..0f06e269 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -59,7 +59,7 @@ typedef ViewInfoCallback = void Function(Channel); /// Modify it to change the widget appearance. class ChannelListView extends StatefulWidget { /// Instantiate a new ChannelListView - const ChannelListView({ + ChannelListView({ Key? key, this.filter, this.sort, @@ -68,9 +68,12 @@ class ChannelListView extends StatefulWidget { this.presence = false, this.memberLimit, this.messageLimit, - this.pagination = const PaginationParams( - limit: 25, - ), + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + this.pagination, + int? limit, this.onChannelTap, this.onChannelLongPress, this.channelWidget, @@ -92,7 +95,8 @@ class ChannelListView extends StatefulWidget { this.onDeletePressed, this.swipeActions, this.channelListController, - }) : super(key: key); + }) : limit = limit ?? pagination?.limit ?? 25, + super(key: key); /// If true a default swipe to action behaviour will be added to this widget final bool swipeToAction; @@ -129,7 +133,14 @@ class ChannelListView extends StatefulWidget { /// limit: the number of channels to return (max is 30) /// offset: the offset (max is 1000) /// message_limit: how many messages should be included to each channel - final PaginationParams pagination; + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + final PaginationParams? pagination; + + /// The amount of channels requested per API call. + final int limit; /// Function called when tapping on a channel /// By default it calls [Navigator.push] building a [MaterialPageRoute] @@ -218,7 +229,7 @@ class _ChannelListViewState extends State { presence: widget.presence, memberLimit: widget.memberLimit, messageLimit: widget.messageLimit, - pagination: widget.pagination, + limit: widget.limit, channelListController: _channelListController, listBuilder: widget.listBuilder ?? _buildListView, emptyBuilder: widget.emptyBuilder ?? _buildEmptyWidget, diff --git a/packages/stream_chat_flutter/lib/src/message_search_list_view.dart b/packages/stream_chat_flutter/lib/src/message_search_list_view.dart index f80c688f..ab1a9178 100644 --- a/packages/stream_chat_flutter/lib/src/message_search_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_search_list_view.dart @@ -53,12 +53,17 @@ typedef EmptyMessageSearchBuilder = Widget Function( /// Modify it to change the widget appearance. class MessageSearchListView extends StatefulWidget { /// Instantiate a new MessageSearchListView - const MessageSearchListView({ + MessageSearchListView({ Key? key, required this.filters, this.messageQuery, this.sortOptions, - this.paginationParams = const PaginationParams(limit: 30), + @Deprecated( + "'paginationParams' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + this.paginationParams, + int? limit, this.messageFilters, this.separatorBuilder, this.itemBuilder, @@ -71,7 +76,8 @@ class MessageSearchListView extends StatefulWidget { this.loadingBuilder, this.childBuilder, this.messageSearchListController, - }) : super(key: key); + }) : limit = limit ?? paginationParams?.limit ?? 30, + super(key: key); /// Message String to search on final String? messageQuery; @@ -93,7 +99,14 @@ class MessageSearchListView extends StatefulWidget { /// limit: the number of users to return (max is 30) /// offset: the offset (max is 1000) /// message_limit: how many messages should be included to each channel - final PaginationParams paginationParams; + @Deprecated( + "'paginationParams' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + final PaginationParams? paginationParams; + + /// The amount of messages requested per API call. + final int limit; /// The message query filters to use. /// You can query on any of the custom fields you've defined on the [Channel]. @@ -152,7 +165,7 @@ class _MessageSearchListViewState extends State { filters: widget.filters, sortOptions: widget.sortOptions, messageQuery: widget.messageQuery, - paginationParams: widget.paginationParams, + limit: widget.limit, messageFilters: widget.messageFilters, messageSearchListController: _messageSearchListController, emptyBuilder: widget.emptyBuilder ?? diff --git a/packages/stream_chat_flutter/lib/src/user_list_view.dart b/packages/stream_chat_flutter/lib/src/user_list_view.dart index 12dbb3ec..b946f800 100644 --- a/packages/stream_chat_flutter/lib/src/user_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/user_list_view.dart @@ -46,12 +46,17 @@ typedef UserItemBuilder = Widget Function(BuildContext, User, bool); /// Modify it to change the widget appearance. class UserListView extends StatefulWidget { /// Instantiate a new UserListView - const UserListView({ + UserListView({ Key? key, this.filter = const Filter.empty(), this.sort, this.presence, - this.pagination = const PaginationParams(limit: 30), + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + this.pagination, + int? limit, this.onUserTap, this.onUserLongPress, this.userWidget, @@ -71,6 +76,7 @@ class UserListView extends StatefulWidget { crossAxisCount == 1 || groupAlphabetically == false, 'Cannot group alphabetically when crossAxisCount > 1', ), + limit = limit ?? pagination?.limit ?? 30, super(key: key); /// The query filters to use. @@ -94,7 +100,14 @@ class UserListView extends StatefulWidget { /// limit: the number of users to return (max is 30) /// offset: the offset (max is 1000) /// message_limit: how many messages should be included to each channel - final PaginationParams pagination; + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + final PaginationParams? pagination; + + /// The amount of users requested per API call. + final int limit; /// Function called when tapping on a channel /// By default it calls [Navigator.push] building a [MaterialPageRoute] @@ -185,7 +198,7 @@ class _UserListViewState extends State ), listBuilder: widget.listBuilder ?? (context, list) => _buildListView(list), - pagination: widget.pagination, + limit: widget.limit, sort: widget.sort, filter: widget.filter, presence: widget.presence, diff --git a/packages/stream_chat_flutter/test/src/theme/channel_list_view_theme_test.dart b/packages/stream_chat_flutter/test/src/theme/channel_list_view_theme_test.dart index 38b1c524..079c01e3 100644 --- a/packages/stream_chat_flutter/test/src/theme/channel_list_view_theme_test.dart +++ b/packages/stream_chat_flutter/test/src/theme/channel_list_view_theme_test.dart @@ -62,7 +62,7 @@ void main() { return Scaffold( body: StreamChannel( channel: MockChannel(), - child: const ChannelListView(), + child: ChannelListView(), ), ); }, diff --git a/packages/stream_chat_flutter/test/src/theme/user_list_view_theme_test.dart b/packages/stream_chat_flutter/test/src/theme/user_list_view_theme_test.dart index a22eebd0..3aa20744 100644 --- a/packages/stream_chat_flutter/test/src/theme/user_list_view_theme_test.dart +++ b/packages/stream_chat_flutter/test/src/theme/user_list_view_theme_test.dart @@ -56,7 +56,7 @@ void main() { home: Builder( builder: (BuildContext context) { _context = context; - return const Scaffold( + return Scaffold( body: UsersBloc( child: UserListView(), ), @@ -85,7 +85,7 @@ void main() { home: Builder( builder: (BuildContext context) { _context = context; - return const Scaffold( + return Scaffold( body: UsersBloc( child: UserListView(), ), diff --git a/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart b/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart index e79a7f1f..d3d6c312 100644 --- a/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart +++ b/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart @@ -56,7 +56,7 @@ import 'package:stream_chat_flutter_core/src/typedef.dart'; /// information about the channels. class ChannelListCore extends StatefulWidget { /// Instantiate a new ChannelListView - const ChannelListCore({ + ChannelListCore({ Key? key, required this.errorBuilder, required this.emptyBuilder, @@ -69,11 +69,15 @@ class ChannelListCore extends StatefulWidget { this.memberLimit, this.messageLimit, this.sort, - this.pagination = const PaginationParams( - limit: 25, - ), + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + this.pagination, this.channelListController, - }) : super(key: key); + int? limit, + }) : limit = limit ?? pagination?.limit ?? 25, + super(key: key); /// A [ChannelListController] allows reloading and pagination. /// Use [ChannelListController.loadData] and @@ -124,7 +128,14 @@ class ChannelListCore extends StatefulWidget { /// limit: the number of channels to return (max is 30) /// offset: the offset (max is 1000) /// message_limit: how many messages should be included to each channel - final PaginationParams pagination; + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + final PaginationParams? pagination; + + /// The amount of channels requested per API call. + final int limit; @override ChannelListCoreState createState() => ChannelListCoreState(); @@ -162,7 +173,7 @@ class ChannelListCoreState extends State { presence: widget.presence, memberLimit: widget.memberLimit, messageLimit: widget.messageLimit, - paginationParams: widget.pagination, + paginationParams: PaginationParams(limit: widget.limit), ); /// Fetches more channels with updated pagination and updates the widget @@ -174,7 +185,8 @@ class ChannelListCoreState extends State { presence: widget.presence, memberLimit: widget.memberLimit, messageLimit: widget.messageLimit, - paginationParams: widget.pagination.copyWith( + paginationParams: PaginationParams( + limit: widget.limit, offset: _channelsBloc.channels?.length ?? 0, ), ); @@ -221,7 +233,7 @@ class ChannelListCoreState extends State { widget.presence != oldWidget.presence || widget.messageLimit != oldWidget.messageLimit || widget.memberLimit != oldWidget.memberLimit || - jsonEncode(widget.pagination) != jsonEncode(oldWidget.pagination)) { + widget.limit != oldWidget.limit) { loadData(); } diff --git a/packages/stream_chat_flutter_core/lib/src/message_search_list_core.dart b/packages/stream_chat_flutter_core/lib/src/message_search_list_core.dart index e5b91b6e..f4d18a0b 100644 --- a/packages/stream_chat_flutter_core/lib/src/message_search_list_core.dart +++ b/packages/stream_chat_flutter_core/lib/src/message_search_list_core.dart @@ -38,7 +38,7 @@ class MessageSearchListCore extends StatefulWidget { /// * [errorBuilder] /// * [loadingBuilder] /// * [childBuilder] - const MessageSearchListCore({ + MessageSearchListCore({ Key? key, required this.emptyBuilder, required this.errorBuilder, @@ -47,9 +47,14 @@ class MessageSearchListCore extends StatefulWidget { required this.filters, this.messageQuery, this.sortOptions, - this.paginationParams = const PaginationParams(limit: 30), + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + this.paginationParams, this.messageFilters, this.messageSearchListController, + int? limit, }) : assert( messageQuery != null || messageFilters != null, 'Provide at least `query` or `messageFilters`', @@ -58,6 +63,13 @@ class MessageSearchListCore extends StatefulWidget { messageQuery == null || messageFilters == null, "Can't provide both `query` and `messageFilters` at the same time", ), + assert( + paginationParams?.offset == null || + paginationParams?.offset == 0 || + sortOptions == null, + 'Cannot specify `offset` with `sortOptions` parameter', + ), + limit = limit ?? paginationParams?.limit ?? 30, super(key: key); /// A [MessageSearchListController] allows reloading and pagination. @@ -84,7 +96,14 @@ class MessageSearchListCore extends StatefulWidget { /// Pagination parameters /// limit: the number of messages to return (max is 30) /// offset: the offset (max is 1000) - final PaginationParams paginationParams; + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + final PaginationParams? paginationParams; + + /// The amount of messages requested per API call. + final int limit; /// The message query filters to use. /// You can query on any of the custom fields you've defined on the [Channel]. @@ -157,19 +176,19 @@ class MessageSearchListCoreState extends State { filter: widget.filters, sort: widget.sortOptions, query: widget.messageQuery, - pagination: widget.paginationParams, messageFilter: widget.messageFilters, + pagination: PaginationParams(limit: widget.limit), ); /// Fetches more messages with updated pagination and updates the widget Future paginateData() { - PaginationParams pagination; + var pagination = PaginationParams(limit: widget.limit); if (widget.sortOptions != null) { - pagination = widget.paginationParams.copyWith( + pagination = pagination.copyWith( next: _messageSearchBloc?.nextId, ); } else { - pagination = widget.paginationParams.copyWith( + pagination = pagination.copyWith( offset: _messageSearchBloc?.messageResponses?.length, ); } @@ -190,8 +209,7 @@ class MessageSearchListCoreState extends State { widget.messageQuery != oldWidget.messageQuery || jsonEncode(widget.messageFilters) != jsonEncode(oldWidget.messageFilters) || - jsonEncode(widget.paginationParams) != - jsonEncode(oldWidget.paginationParams)) { + widget.limit != oldWidget.limit) { loadData(); } diff --git a/packages/stream_chat_flutter_core/lib/src/user_list_core.dart b/packages/stream_chat_flutter_core/lib/src/user_list_core.dart index 75fc7411..839067bf 100644 --- a/packages/stream_chat_flutter_core/lib/src/user_list_core.dart +++ b/packages/stream_chat_flutter_core/lib/src/user_list_core.dart @@ -57,7 +57,7 @@ import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; /// [errorBuilder] must all be supplied and not null. class UserListCore extends StatefulWidget { /// Instantiate a new [UserListCore] - const UserListCore({ + UserListCore({ required this.errorBuilder, required this.emptyBuilder, required this.loadingBuilder, @@ -66,10 +66,16 @@ class UserListCore extends StatefulWidget { this.filter = const Filter.empty(), this.sort, this.presence, - this.pagination = const PaginationParams(limit: 30), + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + this.pagination, this.groupAlphabetically = false, this.userListController, - }) : super(key: key); + int? limit, + }) : limit = limit ?? pagination?.limit ?? 30, + super(key: key); /// A [UserListController] allows reloading and pagination. /// Use [UserListController.loadData] and [UserListController.paginateData] @@ -107,7 +113,14 @@ class UserListCore extends StatefulWidget { /// limit: the number of users to return (max is 30) /// offset: the offset (max is 1000) /// message_limit: how many messages should be included to each channel - final PaginationParams pagination; + @Deprecated( + "'pagination' is deprecated and shouldn't be used. " + "This property is no longer used, Please use 'limit' instead", + ) + final PaginationParams? pagination; + + /// The amount of users requested per API call. + final int limit; /// Set it to true to group users by their first character /// @@ -194,7 +207,7 @@ class UserListCoreState extends State filter: widget.filter, sort: widget.sort, presence: widget.presence, - pagination: widget.pagination, + pagination: PaginationParams(limit: widget.limit), ); /// Fetches more users with updated pagination and updates the widget @@ -202,7 +215,8 @@ class UserListCoreState extends State filter: widget.filter, sort: widget.sort, presence: widget.presence, - pagination: widget.pagination.copyWith( + pagination: PaginationParams( + limit: widget.limit, offset: _usersBloc!.users?.length ?? 0, ), ); @@ -213,7 +227,7 @@ class UserListCoreState extends State if (jsonEncode(widget.filter) != jsonEncode(oldWidget.filter) || jsonEncode(widget.sort) != jsonEncode(oldWidget.sort) || widget.presence != oldWidget.presence || - jsonEncode(widget.pagination) != jsonEncode(oldWidget.pagination)) { + widget.limit != oldWidget.limit) { loadData(); } diff --git a/packages/stream_chat_flutter_core/test/channel_list_core_test.dart b/packages/stream_chat_flutter_core/test/channel_list_core_test.dart index 47aa2bf9..8e8755aa 100644 --- a/packages/stream_chat_flutter_core/test/channel_list_core_test.dart +++ b/packages/stream_chat_flutter_core/test/channel_list_core_test.dart @@ -508,4 +508,18 @@ void main() { )).called(1); }, ); + + test('`widget.limit` should match `widget.pagination.limit`', () { + const pagination = PaginationParams(limit: 30); + final channelListCore = ChannelListCore( + listBuilder: (_, __) => const Offstage(), + loadingBuilder: (BuildContext context) => const Offstage(), + emptyBuilder: (BuildContext context) => const Offstage(), + errorBuilder: (BuildContext context, Object error) => const Offstage(), + pagination: pagination, + ); + + expect(channelListCore.limit, pagination.limit); + }); + } diff --git a/packages/stream_chat_flutter_core/test/message_search_list_core_test.dart b/packages/stream_chat_flutter_core/test/message_search_list_core_test.dart index 02a78412..ca416595 100644 --- a/packages/stream_chat_flutter_core/test/message_search_list_core_test.dart +++ b/packages/stream_chat_flutter_core/test/message_search_list_core_test.dart @@ -551,4 +551,19 @@ void main() { )).called(1); }, ); + + test('`widget.limit` should match `widget.pagination.limit`', () { + const pagination = PaginationParams(limit: 30); + final messageSearchListCore = MessageSearchListCore( + childBuilder: (List messages) => const Offstage(), + loadingBuilder: (BuildContext context) => const Offstage(), + emptyBuilder: (BuildContext context) => const Offstage(), + errorBuilder: (BuildContext context, Object? error) => const Offstage(), + filters: testFilter, + messageFilters: testMessageFilter, + paginationParams: pagination, + ); + + expect(messageSearchListCore.limit, pagination.limit); + }); } diff --git a/packages/stream_chat_flutter_core/test/user_list_core_test.dart b/packages/stream_chat_flutter_core/test/user_list_core_test.dart index 77977bb8..ade58e0f 100644 --- a/packages/stream_chat_flutter_core/test/user_list_core_test.dart +++ b/packages/stream_chat_flutter_core/test/user_list_core_test.dart @@ -520,4 +520,17 @@ void main() { )).called(1); }, ); + + test('`widget.limit` should match `widget.pagination.limit`', () { + const pagination = PaginationParams(limit: 30); + final userListCore = UserListCore( + listBuilder: (_, __) => const Offstage(), + loadingBuilder: (BuildContext context) => const Offstage(), + emptyBuilder: (BuildContext context) => const Offstage(), + errorBuilder: (BuildContext context, Object error) => const Offstage(), + pagination: pagination, + ); + + expect(userListCore.limit, pagination.limit); + }); } From d9ced67f80f6dfcc1a981ff4c878942cc05a4df7 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 15 Sep 2021 21:02:29 +0530 Subject: [PATCH 2/3] chore(ui, core): update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 22 ++++++++++++++++--- .../stream_chat_flutter_core/CHANGELOG.md | 22 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index b2ef50cb..16db1398 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,14 +1,30 @@ ## 2.2.1 -🛑️ Breaking Changes from `2.2.1` +⚠️ Deprecated -- `MessageSearchListView` paginationParams property is now non-nullable with a default value. +- `MessageSearchListView` `paginationParams` property is now deprecated in favor of `limit`. ```dart + // previous paginationParams = const PaginationParams(limit: 30) + + // new + limit = 30 ``` -- `UserListView` pagination property is now non-nullable with a default value. +- `UserListView` `pagination` property is now deprecated in favor of `limit`. ```dart + // previous pagination = const PaginationParams(limit: 30) + + // new + limit = 30 + ``` +- `ChannelListView` `pagination` property is now deprecated in favor of `limit`. + ```dart + // previous + pagination = const PaginationParams(limit: 30) + + // new + limit = 30 ``` 🔄 Changed diff --git a/packages/stream_chat_flutter_core/CHANGELOG.md b/packages/stream_chat_flutter_core/CHANGELOG.md index 5ce1eb8b..c4287a09 100644 --- a/packages/stream_chat_flutter_core/CHANGELOG.md +++ b/packages/stream_chat_flutter_core/CHANGELOG.md @@ -1,14 +1,30 @@ ## Upcoming -🛑️ Breaking Changes from `2.2.1` +⚠️ Deprecated -- `MessageSearchListViewCore` paginationParams property is now non-nullable with a default value. +- `MessageSearchListViewCore` `paginationParams` property is now deprecated in favor of `limit`. ```dart + // previous paginationParams = const PaginationParams(limit: 30) + + // new + limit = 30 ``` -- `UserListViewCore` pagination property is now non-nullable with a default value. +- `UserListViewCore` `pagination` property is now deprecated in favor of `limit`. ```dart + // previous pagination = const PaginationParams(limit: 30) + + // new + limit = 30 + ``` +- `ChannelListViewCore` `pagination` property is now deprecated in favor of `limit`. + ```dart + // previous + pagination = const PaginationParams(limit: 30) + + // new + limit = 30 ``` 🔄 Changed From 9a70beb33dae74c523248f3cbe737e6a925e6de2 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 16 Sep 2021 11:43:04 +0200 Subject: [PATCH 3/3] chore(core): fix format --- .../stream_chat_flutter_core/test/channel_list_core_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/stream_chat_flutter_core/test/channel_list_core_test.dart b/packages/stream_chat_flutter_core/test/channel_list_core_test.dart index 8e8755aa..dd87d2cf 100644 --- a/packages/stream_chat_flutter_core/test/channel_list_core_test.dart +++ b/packages/stream_chat_flutter_core/test/channel_list_core_test.dart @@ -521,5 +521,4 @@ void main() { expect(channelListCore.limit, pagination.limit); }); - }