Merge pull request #514 from GetStream/feat/listControllers
feat: list controllers
This commit is contained in:
@@ -89,6 +89,7 @@ class ChannelListView extends StatefulWidget {
|
|||||||
this.onMoreDetailsPressed,
|
this.onMoreDetailsPressed,
|
||||||
this.onDeletePressed,
|
this.onDeletePressed,
|
||||||
this.swipeActions,
|
this.swipeActions,
|
||||||
|
this.channelListController,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// If true a default swipe to action behaviour will be added to this widget
|
/// 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
|
/// List of actions for slidable
|
||||||
final List<SwipeAction>? swipeActions;
|
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
|
@override
|
||||||
_ChannelListViewState createState() => _ChannelListViewState();
|
_ChannelListViewState createState() => _ChannelListViewState();
|
||||||
}
|
}
|
||||||
@@ -194,7 +201,9 @@ class ChannelListView extends StatefulWidget {
|
|||||||
class _ChannelListViewState extends State<ChannelListView> {
|
class _ChannelListViewState extends State<ChannelListView> {
|
||||||
final _slideController = SlidableController();
|
final _slideController = SlidableController();
|
||||||
|
|
||||||
final _channelListController = ChannelListController();
|
late final _defaultController = ChannelListController();
|
||||||
|
ChannelListController get _channelListController =>
|
||||||
|
widget.channelListController ?? _defaultController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ class MessageListView extends StatefulWidget {
|
|||||||
this.usernameBuilder,
|
this.usernameBuilder,
|
||||||
this.showFloatingDateDivider = true,
|
this.showFloatingDateDivider = true,
|
||||||
this.threadSeparatorBuilder,
|
this.threadSeparatorBuilder,
|
||||||
|
this.messageListController,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// 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
|
/// Builder used to build the thread separator in case it's a thread view
|
||||||
final WidgetBuilder? threadSeparatorBuilder;
|
final WidgetBuilder? threadSeparatorBuilder;
|
||||||
|
|
||||||
|
/// A [MessageListController] allows pagination.
|
||||||
|
/// Use [ChannelListController.paginateData] pagination.
|
||||||
|
final MessageListController? messageListController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageListViewState createState() => _MessageListViewState();
|
_MessageListViewState createState() => _MessageListViewState();
|
||||||
}
|
}
|
||||||
@@ -347,7 +352,9 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
|
|
||||||
bool _inBetweenList = false;
|
bool _inBetweenList = false;
|
||||||
|
|
||||||
final MessageListController _messageListController = MessageListController();
|
late final _defaultController = MessageListController();
|
||||||
|
MessageListController get _messageListController =>
|
||||||
|
widget.messageListController ?? _defaultController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => MessageListCore(
|
Widget build(BuildContext context) => MessageListCore(
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class MessageSearchListView extends StatefulWidget {
|
|||||||
this.errorBuilder,
|
this.errorBuilder,
|
||||||
this.loadingBuilder,
|
this.loadingBuilder,
|
||||||
this.childBuilder,
|
this.childBuilder,
|
||||||
|
this.messageSearchListController,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message String to search on
|
/// Message String to search on
|
||||||
@@ -127,13 +128,20 @@ class MessageSearchListView extends StatefulWidget {
|
|||||||
/// The builder that will be used in case of loading
|
/// The builder that will be used in case of loading
|
||||||
final WidgetBuilder? loadingBuilder;
|
final WidgetBuilder? loadingBuilder;
|
||||||
|
|
||||||
|
/// A [MessageSearchListController] allows reloading and pagination.
|
||||||
|
/// Use [MessageSearchListController.loadData] and
|
||||||
|
/// [MessageSearchListController.paginateData] respectively for reloading and
|
||||||
|
/// pagination.
|
||||||
|
final MessageSearchListController? messageSearchListController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageSearchListViewState createState() => _MessageSearchListViewState();
|
_MessageSearchListViewState createState() => _MessageSearchListViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MessageSearchListViewState extends State<MessageSearchListView> {
|
class _MessageSearchListViewState extends State<MessageSearchListView> {
|
||||||
final MessageSearchListController _messageSearchListController =
|
late final _defaultController = MessageSearchListController();
|
||||||
MessageSearchListController();
|
MessageSearchListController get _messageSearchListController =>
|
||||||
|
widget.messageSearchListController ?? _defaultController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => MessageSearchListCore(
|
Widget build(BuildContext context) => MessageSearchListCore(
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class UserListView extends StatefulWidget {
|
|||||||
this.emptyBuilder,
|
this.emptyBuilder,
|
||||||
this.loadingBuilder,
|
this.loadingBuilder,
|
||||||
this.listBuilder,
|
this.listBuilder,
|
||||||
|
this.userListController,
|
||||||
}) : assert(
|
}) : assert(
|
||||||
crossAxisCount == 1 || groupAlphabetically == false,
|
crossAxisCount == 1 || groupAlphabetically == false,
|
||||||
'Cannot group alphabetically when crossAxisCount > 1',
|
'Cannot group alphabetically when crossAxisCount > 1',
|
||||||
@@ -140,6 +141,11 @@ class UserListView extends StatefulWidget {
|
|||||||
/// The builder used when the channel list is empty.
|
/// The builder used when the channel list is empty.
|
||||||
final WidgetBuilder? emptyBuilder;
|
final WidgetBuilder? emptyBuilder;
|
||||||
|
|
||||||
|
/// A [UserListController] allows reloading and pagination.
|
||||||
|
/// Use [UserListController.loadData] and [UserListController.paginateData]
|
||||||
|
/// respectively for reloading and pagination.
|
||||||
|
final UserListController? userListController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_UserListViewState createState() => _UserListViewState();
|
_UserListViewState createState() => _UserListViewState();
|
||||||
}
|
}
|
||||||
@@ -148,7 +154,9 @@ class _UserListViewState extends State<UserListView>
|
|||||||
with WidgetsBindingObserver {
|
with WidgetsBindingObserver {
|
||||||
bool get _isListView => widget.crossAxisCount == 1;
|
bool get _isListView => widget.crossAxisCount == 1;
|
||||||
|
|
||||||
final UserListController _userListController = UserListController();
|
late final _defaultController = UserListController();
|
||||||
|
UserListController get _userListController =>
|
||||||
|
widget.userListController ?? _defaultController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
@@ -114,15 +114,24 @@ class MessageSearchListCoreState extends State<MessageSearchListCore> {
|
|||||||
if (newMessageSearchBloc != _messageSearchBloc) {
|
if (newMessageSearchBloc != _messageSearchBloc) {
|
||||||
_messageSearchBloc = newMessageSearchBloc;
|
_messageSearchBloc = newMessageSearchBloc;
|
||||||
loadData();
|
loadData();
|
||||||
if (widget.messageSearchListController != null) {
|
|
||||||
widget.messageSearchListController!.loadData = loadData;
|
|
||||||
widget.messageSearchListController!.paginateData = paginateData;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _setupController() {
|
||||||
|
if (widget.messageSearchListController != null) {
|
||||||
|
widget.messageSearchListController!.loadData = loadData;
|
||||||
|
widget.messageSearchListController!.paginateData = paginateData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_setupController();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => _buildListView(_messageSearchBloc!);
|
Widget build(BuildContext context) => _buildListView(_messageSearchBloc!);
|
||||||
|
|
||||||
@@ -176,6 +185,11 @@ class MessageSearchListCoreState extends State<MessageSearchListCore> {
|
|||||||
oldWidget.paginationParams?.toJson().toString()) {
|
oldWidget.paginationParams?.toJson().toString()) {
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (widget.messageSearchListController !=
|
||||||
|
oldWidget.messageSearchListController) {
|
||||||
|
_setupController();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,14 +128,23 @@ class UserListCoreState extends State<UserListCore>
|
|||||||
if (newUsersBloc != _usersBloc) {
|
if (newUsersBloc != _usersBloc) {
|
||||||
_usersBloc = newUsersBloc;
|
_usersBloc = newUsersBloc;
|
||||||
loadData();
|
loadData();
|
||||||
if (widget.userListController != null) {
|
|
||||||
widget.userListController!.loadData = loadData;
|
|
||||||
widget.userListController!.paginateData = paginateData;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_setupController();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setupController() {
|
||||||
|
if (widget.userListController != null) {
|
||||||
|
widget.userListController!.loadData = loadData;
|
||||||
|
widget.userListController!.paginateData = paginateData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => _buildListView();
|
Widget build(BuildContext context) => _buildListView();
|
||||||
|
|
||||||
@@ -212,6 +221,10 @@ class UserListCoreState extends State<UserListCore>
|
|||||||
oldWidget.pagination?.toJson().toString()) {
|
oldWidget.pagination?.toJson().toString()) {
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (widget.userListController != oldWidget.userListController) {
|
||||||
|
_setupController();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user