use comparator
This commit is contained in:
@@ -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
|
/// 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
|
/// Comparator used to sort the channels when a message.new event is received
|
||||||
final List<Channel> Function(List<Channel>) sortChannels;
|
final Comparator<Channel> channelsComparator;
|
||||||
|
|
||||||
/// 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,
|
this.channelsComparator,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -146,12 +146,10 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.sortChannels != null) {
|
if (widget.channelsComparator != null) {
|
||||||
final sortedChannels = widget.sortChannels(newChannels);
|
newChannels.sort(widget.channelsComparator);
|
||||||
_channelsController.add(sortedChannels);
|
|
||||||
} else {
|
|
||||||
_channelsController.add(newChannels);
|
|
||||||
}
|
}
|
||||||
|
_channelsController.add(newChannels);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user