withEdit method

MaterialFile withEdit(
  1. MaterialFile edited, {
  2. MaterialFile? shown,
})

edited keeping, as a variant, every key it changed as an override.

edited is a copyWith of shown — what was on screen: this variant resolved over its parents, so a value set equal to this file's own default still counts — or of this file when shown is null.

Implementation

MaterialFile withEdit(MaterialFile edited, {MaterialFile? shown}) {
  if (!isVariant) return edited;
  final before = (shown ?? this)._all();
  final after = edited._all();
  return edited.copyWith(
    parent: parent,
    overrides: {
      ...overrides,
      for (final k in keys)
        if (jsonEncode(before[k]) != jsonEncode(after[k])) k,
    },
  );
}