diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 2312ff12..1d5d3f92 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -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 final bool lockChannelsOrder; + /// Function used to sort the channels when a message.new event is received + final List Function(List) sortChannels; + /// Instantiate a new ChannelsBloc const ChannelsBloc({ Key key, this.child, this.lockChannelsOrder = false, + this.sortChannels, }) : super(key: key); @override @@ -58,11 +62,6 @@ class ChannelsBlocState extends State final BehaviorSubject> _channelsController = BehaviorSubject(); - /// Set the current channel list - set channels(List newChannels) { - _channelsController.add(newChannels); - } - /// The stream notifying the state of queryChannel call Stream get queryChannelsLoading => _queryChannelsLoadingController.stream; @@ -146,7 +145,13 @@ class ChannelsBlocState extends State } } } - _channelsController.add(newChannels); + + if (widget.sortChannels != null) { + final sortedChannels = widget.sortChannels(newChannels); + _channelsController.add(sortedChannels); + } else { + _channelsController.add(newChannels); + } })); }