add change it to a function called at the end of the message.new event handler
This commit is contained in:
@@ -14,11 +14,15 @@ class ChannelsBloc extends StatefulWidget {
|
|||||||
/// Set this to true to prevent channels to be brought to the top of the list when a new message arrives
|
/// Set this to true to prevent channels to be brought to the top of the list when a new message arrives
|
||||||
final bool lockChannelsOrder;
|
final bool lockChannelsOrder;
|
||||||
|
|
||||||
|
/// Function used to sort the channels when a message.new event is received
|
||||||
|
final List<Channel> Function(List<Channel>) sortChannels;
|
||||||
|
|
||||||
/// Instantiate a new ChannelsBloc
|
/// Instantiate a new ChannelsBloc
|
||||||
const ChannelsBloc({
|
const ChannelsBloc({
|
||||||
Key key,
|
Key key,
|
||||||
this.child,
|
this.child,
|
||||||
this.lockChannelsOrder = false,
|
this.lockChannelsOrder = false,
|
||||||
|
this.sortChannels,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -58,11 +62,6 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
|
|
||||||
final BehaviorSubject<List<Channel>> _channelsController = BehaviorSubject();
|
final BehaviorSubject<List<Channel>> _channelsController = BehaviorSubject();
|
||||||
|
|
||||||
/// Set the current channel list
|
|
||||||
set channels(List<Channel> newChannels) {
|
|
||||||
_channelsController.add(newChannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The stream notifying the state of queryChannel call
|
/// The stream notifying the state of queryChannel call
|
||||||
Stream<bool> get queryChannelsLoading =>
|
Stream<bool> get queryChannelsLoading =>
|
||||||
_queryChannelsLoadingController.stream;
|
_queryChannelsLoadingController.stream;
|
||||||
@@ -146,7 +145,13 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_channelsController.add(newChannels);
|
|
||||||
|
if (widget.sortChannels != null) {
|
||||||
|
final sortedChannels = widget.sortChannels(newChannels);
|
||||||
|
_channelsController.add(sortedChannels);
|
||||||
|
} else {
|
||||||
|
_channelsController.add(newChannels);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user