SourceEdit.fromJson constructor

SourceEdit.fromJson(
  1. Map<String, dynamic> json
)

Constructs a SourceEdit from JSON.

Example:

final edit = {
  'offset': 1,
  'length': 2,
  'replacement': 'replacement string'
};

final sourceEdit = SourceEdit.fromJson(edit);

Implementation

factory SourceEdit.fromJson(Map<String, dynamic> json) {
  final offset = json['offset'];
  final length = json['length'];
  final replacement = json['replacement'];

  if (offset is int && length is int && replacement is String) {
    return SourceEdit(offset, length, replacement);
  }

  throw const FormatException('Invalid JSON passed to SourceEdit');
}