accept list controllers as params in ui package listviews

This commit is contained in:
Salvatore Giordano
2021-06-29 11:29:42 +02:00
parent 5cb87d2df5
commit 81b69e95bf
4 changed files with 33 additions and 5 deletions
@@ -89,6 +89,7 @@ class ChannelListView extends StatefulWidget {
this.onMoreDetailsPressed,
this.onDeletePressed,
this.swipeActions,
this.channelListController,
}) : super(key: key);
/// If true a default swipe to action behaviour will be added to this widget
@@ -187,6 +188,12 @@ class ChannelListView extends StatefulWidget {
/// List of actions for slidable
final List<SwipeAction>? swipeActions;
/// A [ChannelListController] allows reloading and pagination.
/// Use [ChannelListController.loadData] and
/// [ChannelListController.paginateData] respectively for reloading and
/// pagination.
final ChannelListController? channelListController;
@override
_ChannelListViewState createState() => _ChannelListViewState();
}
@@ -194,7 +201,8 @@ class ChannelListView extends StatefulWidget {
class _ChannelListViewState extends State<ChannelListView> {
final _slideController = SlidableController();
final _channelListController = ChannelListController();
late final _channelListController =
widget.channelListController ?? ChannelListController();
@override
Widget build(BuildContext context) {
@@ -172,6 +172,7 @@ class MessageListView extends StatefulWidget {
this.usernameBuilder,
this.showFloatingDateDivider = true,
this.threadSeparatorBuilder,
this.messageListController,
}) : super(key: key);
/// Function used to build a custom message widget
@@ -296,6 +297,10 @@ class MessageListView extends StatefulWidget {
/// Builder used to build the thread separator in case it's a thread view
final WidgetBuilder? threadSeparatorBuilder;
/// A [MessageListController] allows pagination.
/// Use [ChannelListController.paginateData] pagination.
final MessageListController? messageListController;
@override
_MessageListViewState createState() => _MessageListViewState();
}
@@ -347,7 +352,8 @@ class _MessageListViewState extends State<MessageListView> {
bool _inBetweenList = false;
final MessageListController _messageListController = MessageListController();
late final MessageListController _messageListController =
widget.messageListController ?? MessageListController();
@override
Widget build(BuildContext context) => MessageListCore(
@@ -68,6 +68,7 @@ class MessageSearchListView extends StatefulWidget {
this.errorBuilder,
this.loadingBuilder,
this.childBuilder,
this.messageSearchListController,
}) : super(key: key);
/// Message String to search on
@@ -127,13 +128,19 @@ class MessageSearchListView extends StatefulWidget {
/// The builder that will be used in case of loading
final WidgetBuilder? loadingBuilder;
/// A [MessageSearchListController] allows reloading and pagination.
/// Use [MessageSearchListController.loadData] and
/// [MessageSearchListController.paginateData] respectively for reloading and
/// pagination.
final MessageSearchListController? messageSearchListController;
@override
_MessageSearchListViewState createState() => _MessageSearchListViewState();
}
class _MessageSearchListViewState extends State<MessageSearchListView> {
final MessageSearchListController _messageSearchListController =
MessageSearchListController();
late final MessageSearchListController _messageSearchListController =
widget.messageSearchListController ?? MessageSearchListController();
@override
Widget build(BuildContext context) => MessageSearchListCore(
@@ -64,6 +64,7 @@ class UserListView extends StatefulWidget {
this.emptyBuilder,
this.loadingBuilder,
this.listBuilder,
this.userListController,
}) : assert(
crossAxisCount == 1 || groupAlphabetically == false,
'Cannot group alphabetically when crossAxisCount > 1',
@@ -140,6 +141,11 @@ class UserListView extends StatefulWidget {
/// The builder used when the channel list is empty.
final WidgetBuilder? emptyBuilder;
/// A [UserListController] allows reloading and pagination.
/// Use [UserListController.loadData] and [UserListController.paginateData]
/// respectively for reloading and pagination.
final UserListController? userListController;
@override
_UserListViewState createState() => _UserListViewState();
}
@@ -148,7 +154,8 @@ class _UserListViewState extends State<UserListView>
with WidgetsBindingObserver {
bool get _isListView => widget.crossAxisCount == 1;
final UserListController _userListController = UserListController();
late final UserListController _userListController =
widget.userListController ?? UserListController();
@override
Widget build(BuildContext context) {