From 422df24e9f36b7aec818a2292c2bae2d325f4f23 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 17 Dec 2020 11:15:25 +0100 Subject: [PATCH] use comparator --- lib/src/channels_bloc.dart | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 1d5d3f92..59dd6335 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -14,15 +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; + /// Comparator used to sort the channels when a message.new event is received + final Comparator channelsComparator; /// Instantiate a new ChannelsBloc const ChannelsBloc({ Key key, this.child, this.lockChannelsOrder = false, - this.sortChannels, + this.channelsComparator, }) : super(key: key); @override @@ -146,12 +146,10 @@ class ChannelsBlocState extends State } } - if (widget.sortChannels != null) { - final sortedChannels = widget.sortChannels(newChannels); - _channelsController.add(sortedChannels); - } else { - _channelsController.add(newChannels); + if (widget.channelsComparator != null) { + newChannels.sort(widget.channelsComparator); } + _channelsController.add(newChannels); })); }