ListDifference<T> constructor

ListDifference<T>({
  1. List<T> initialValues = const [],
  2. List<T> currentValues = const [],
  3. bool containsValidator(
    1. List<T> elements,
    2. T e
    )?,
})

Implementation

ListDifference({
  List<T> initialValues = const [],
  List<T> currentValues = const [],
  this.containsValidator,
}) {
  final List<T> initial = initialValues.removeDuplicates();
  final List<T> current = currentValues.removeDuplicates();

  if (!listEquals(initial, current)) {
    if (initial.isEmpty) {
      added.addAll(current);
    } else {
      for (final item in initial) {
        if (!_validator(current, item)) removed.add(item);
      }
      for (final item in current) {
        if (!_validator(initial, item)) added.add(item);
      }
    }
    equals.addAll(currentValues.where((e) => _validator(initialValues, e)));
  } else {
    equals.addAll(current);
  }
}