perform heavy calls only first time
This commit is contained in:
@@ -1087,8 +1087,6 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
_itemPositionListener =
|
_itemPositionListener =
|
||||||
widget.itemPositionListener ?? ItemPositionsListener.create();
|
widget.itemPositionListener ?? ItemPositionsListener.create();
|
||||||
|
|
||||||
streamChannel = StreamChannel.of(context);
|
|
||||||
|
|
||||||
initialIndex = _initialIndex;
|
initialIndex = _initialIndex;
|
||||||
initialAlignment = _initialAlignment;
|
initialAlignment = _initialAlignment;
|
||||||
|
|
||||||
@@ -1100,6 +1098,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
streamChannel = StreamChannel.of(context);
|
streamChannel = StreamChannel.of(context);
|
||||||
|
|
||||||
|
if (_messageNewListener == null) {
|
||||||
_messageNewListener?.cancel();
|
_messageNewListener?.cancel();
|
||||||
_messageNewListener =
|
_messageNewListener =
|
||||||
streamChannel.channel.on(EventType.messageNew).listen((event) {
|
streamChannel.channel.on(EventType.messageNew).listen((event) {
|
||||||
@@ -1120,6 +1119,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
if (_isThreadConversation) {
|
if (_isThreadConversation) {
|
||||||
streamChannel.getReplies(widget.parentMessage!.id);
|
streamChannel.getReplies(widget.parentMessage!.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,10 +178,7 @@ class ChannelListCoreState extends State<ChannelListCore> {
|
|||||||
|
|
||||||
if (_subscription == null) {
|
if (_subscription == null) {
|
||||||
loadData();
|
loadData();
|
||||||
}
|
|
||||||
|
|
||||||
final client = _streamChatCoreState.client;
|
final client = _streamChatCoreState.client;
|
||||||
_subscription?.cancel();
|
|
||||||
_subscription = client
|
_subscription = client
|
||||||
.on(
|
.on(
|
||||||
EventType.connectionRecovered,
|
EventType.connectionRecovered,
|
||||||
@@ -190,6 +187,7 @@ class ChannelListCoreState extends State<ChannelListCore> {
|
|||||||
EventType.channelVisible,
|
EventType.channelVisible,
|
||||||
)
|
)
|
||||||
.listen((event) => loadData());
|
.listen((event) => loadData());
|
||||||
|
}
|
||||||
|
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
_streamChatCoreState = StreamChatCore.of(context);
|
_streamChatCoreState = StreamChatCore.of(context);
|
||||||
final client = _streamChatCoreState.client;
|
final client = _streamChatCoreState.client;
|
||||||
|
|
||||||
_cancelSubscriptions();
|
if (_subscriptions.isEmpty) {
|
||||||
if (!widget.lockChannelsOrder) {
|
if (!widget.lockChannelsOrder) {
|
||||||
_subscriptions.add(client
|
_subscriptions.add(client
|
||||||
.on(
|
.on(
|
||||||
@@ -164,7 +164,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
newChannels.insert(0, channel);
|
newChannels.insert(0, channel);
|
||||||
}
|
}
|
||||||
} else if (widget.shouldAddChannel?.call(e) == true) {
|
} else if (widget.shouldAddChannel?.call(e) == true) {
|
||||||
final hiddenIndex = _hiddenChannels.indexWhere((c) => c.cid == e.cid);
|
final hiddenIndex =
|
||||||
|
_hiddenChannels.indexWhere((c) => c.cid == e.cid);
|
||||||
if (hiddenIndex != -1) {
|
if (hiddenIndex != -1) {
|
||||||
newChannels.insert(0, _hiddenChannels[hiddenIndex]);
|
newChannels.insert(0, _hiddenChannels[hiddenIndex]);
|
||||||
_hiddenChannels.removeAt(hiddenIndex);
|
_hiddenChannels.removeAt(hiddenIndex);
|
||||||
@@ -185,7 +186,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
_subscriptions
|
_subscriptions
|
||||||
..add(client.on(EventType.channelHidden).listen((event) async {
|
..add(client.on(EventType.channelHidden).listen((event) async {
|
||||||
final newChannels = List<Channel>.from(channels ?? []);
|
final newChannels = List<Channel>.from(channels ?? []);
|
||||||
final channelIndex = newChannels.indexWhere((c) => c.cid == event.cid);
|
final channelIndex =
|
||||||
|
newChannels.indexWhere((c) => c.cid == event.cid);
|
||||||
if (channelIndex > -1) {
|
if (channelIndex > -1) {
|
||||||
final channel = newChannels.removeAt(channelIndex);
|
final channel = newChannels.removeAt(channelIndex);
|
||||||
_hiddenChannels.add(channel);
|
_hiddenChannels.add(channel);
|
||||||
@@ -202,6 +204,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
_channelsController.add(List.from(
|
_channelsController.add(List.from(
|
||||||
(channels ?? [])..removeWhere((c) => c.cid == channel?.cid)));
|
(channels ?? [])..removeWhere((c) => c.cid == channel?.cid)));
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,10 +173,13 @@ class MessageListCoreState extends State<MessageListCore> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _initialized = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
_streamChannel = StreamChannel.of(context);
|
_streamChannel = StreamChannel.of(context);
|
||||||
if (_isThreadConversation) {
|
if (!_initialized && _isThreadConversation) {
|
||||||
|
_initialized = true;
|
||||||
_streamChannel.getReplies(widget.parentMessage!.id);
|
_streamChannel.getReplies(widget.parentMessage!.id);
|
||||||
}
|
}
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
|||||||
@@ -107,10 +107,17 @@ class MessageSearchListCore extends StatefulWidget {
|
|||||||
class MessageSearchListCoreState extends State<MessageSearchListCore> {
|
class MessageSearchListCoreState extends State<MessageSearchListCore> {
|
||||||
late MessageSearchBlocState _messageSearchBloc;
|
late MessageSearchBlocState _messageSearchBloc;
|
||||||
|
|
||||||
|
var _initialized = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
_messageSearchBloc = MessageSearchBloc.of(context);
|
_messageSearchBloc = MessageSearchBloc.of(context);
|
||||||
|
|
||||||
|
if (!_initialized) {
|
||||||
loadData();
|
loadData();
|
||||||
|
_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (widget.messageSearchListController != null) {
|
if (widget.messageSearchListController != null) {
|
||||||
widget.messageSearchListController!.loadData = loadData;
|
widget.messageSearchListController!.loadData = loadData;
|
||||||
widget.messageSearchListController!.paginateData = paginateData;
|
widget.messageSearchListController!.paginateData = paginateData;
|
||||||
|
|||||||
@@ -122,9 +122,14 @@ class UserListCore extends StatefulWidget {
|
|||||||
/// The current state of the [UserListCore].
|
/// The current state of the [UserListCore].
|
||||||
class UserListCoreState extends State<UserListCore>
|
class UserListCoreState extends State<UserListCore>
|
||||||
with WidgetsBindingObserver {
|
with WidgetsBindingObserver {
|
||||||
|
var _initialized = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
|
if (!_initialized) {
|
||||||
loadData();
|
loadData();
|
||||||
|
_initialized = true;
|
||||||
|
}
|
||||||
if (widget.userListController != null) {
|
if (widget.userListController != null) {
|
||||||
widget.userListController!.loadData = loadData;
|
widget.userListController!.loadData = loadData;
|
||||||
widget.userListController!.paginateData = paginateData;
|
widget.userListController!.paginateData = paginateData;
|
||||||
|
|||||||
Reference in New Issue
Block a user