shuffle method Null safety

  1. @override
void shuffle(
  1. [Random? random]
)
override

Shuffles the elements of this list randomly.

Implementation

@override
void shuffle([Random? random]) {
  _context.conditionallyRunInAction(() {
    if (_list.isNotEmpty) {
      final oldList = _list.toList(growable: false);
      _list.shuffle(random);
      final changes = <ElementChange<T>>[];
      for (var i = 0; i < _list.length; ++i) {
        final oldValue = oldList[i];
        final newValue = _list[i];
        if (newValue != oldValue) {
          changes.add(ElementChange(
              index: i, oldValue: oldValue, newValue: newValue));
        }
      }
      if (changes.isNotEmpty) {
        _notifyElementsUpdate(changes);
      }
    }
  }, _atom);
}