addToModelDecoders static method

String? addToModelDecoders(
  1. String file,
  2. String entries
)

Adds entries to the end of the modelDecoders map in file.

The map's closing brace is found by counting braces, so entries that contain their own { }, such as a OneOf.byKey map, don't cut the map short. Returns null when the map can't be found.

Implementation

static String? addToModelDecoders(String file, String entries) {
  const String declaration = 'final Map<Type, dynamic> modelDecoders = {';
  int start = file.indexOf(declaration);
  if (start == -1) return null;

  int open = start + declaration.length - 1;
  int? close = _closingBrace(file, open);
  if (close == null) return null;

  return file.replaceRange(close, close, '\n$entries');
}