sortAndRandom method Null safety

void sortAndRandom()

Implementation

void sortAndRandom() {
  final random = Random();
  for (final Announcement i in data ?? []) {
    i.randomWeight = random.nextInt(1000);
  }
  data?.sort((a, b) {
    final compare = b.weight!.compareTo(a.weight!);
    final compareRandom = b.randomWeight!.compareTo(a.randomWeight!);
    return compare == 0 ? compareRandom : compare;
  });
}