toListByTime method
Returns a sorted list reorder by time from the oldest to the earliest.
The order is reversed if reversed
is true.
Implementation
List<T> toListByTime({reversed = false}) {
final orderedMessages = toList(growable: false);
try {
orderedMessages.sort(reversed
? (first, second) {
return (first as ItemSerializableWithCreationTime)
.creationTimeStamp -
(second as ItemSerializableWithCreationTime)
.creationTimeStamp;
}
: (first, second) {
return (second as ItemSerializableWithCreationTime)
.creationTimeStamp -
(first as ItemSerializableWithCreationTime).creationTimeStamp;
});
} catch (_) {
TypeException(
'The list should be made from TimedItemSerializable items to use '
'sortByCreationTime.');
}
return orderedMessages;
}