From dde047b0e9bfdb1dcb5961faddc7dc1228c9fd9a Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 29 Jun 2021 12:00:40 +0200 Subject: [PATCH] fix message and user list core controller setup --- .../lib/src/message_search_list_core.dart | 20 +++++++++++++++---- .../lib/src/user_list_core.dart | 19 ++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) 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 a1eb5d683..636a879fa 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 @@ -114,15 +114,22 @@ class MessageSearchListCoreState extends State { if (newMessageSearchBloc != _messageSearchBloc) { _messageSearchBloc = newMessageSearchBloc; loadData(); - if (widget.messageSearchListController != null) { - widget.messageSearchListController!.loadData = loadData; - widget.messageSearchListController!.paginateData = paginateData; - } } super.didChangeDependencies(); } + void _setupController() { + widget.messageSearchListController!.loadData = loadData; + widget.messageSearchListController!.paginateData = paginateData; + } + + @override + void initState() { + super.initState(); + _setupController(); + } + @override Widget build(BuildContext context) => _buildListView(_messageSearchBloc!); @@ -176,6 +183,11 @@ class MessageSearchListCoreState extends State { oldWidget.paginationParams?.toJson().toString()) { loadData(); } + + if (widget.messageSearchListController != + oldWidget.messageSearchListController) { + _setupController(); + } } } 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 e7deb356c..05a8432da 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 @@ -128,14 +128,21 @@ class UserListCoreState extends State if (newUsersBloc != _usersBloc) { _usersBloc = newUsersBloc; loadData(); - if (widget.userListController != null) { - widget.userListController!.loadData = loadData; - widget.userListController!.paginateData = paginateData; - } } super.didChangeDependencies(); } + @override + void initState() { + super.initState(); + _setupController(); + } + + void _setupController() { + widget.userListController!.loadData = loadData; + widget.userListController!.paginateData = paginateData; + } + @override Widget build(BuildContext context) => _buildListView(); @@ -212,6 +219,10 @@ class UserListCoreState extends State oldWidget.pagination?.toJson().toString()) { loadData(); } + + if (widget.userListController != oldWidget.userListController) { + _setupController(); + } } }