parse<T extends PresetValue<T>> static method

Map<String, dynamic> parse<T extends PresetValue<T>>(
  1. String source
)

Retrieve an instance of PresetValue of type T from context. The returned instance of T will be in it's encoded form. Implement T.fromJson to decode an actual instance of T from the data returned.

Implementation

static Map<String, dynamic> parse<T extends PresetValue<T>>(String source) {
  //...
  final regex = RegExp(r'(\w+)(<[\w,]>)?\(({[:\w\s,"{}.]*\})\)');
  final match = regex.matchAsPrefix(source); // regex match data

  try {
    if (match != null) {
      if (match.group(1)?.contains('$T') ?? false) {
        return json.decode(match.group(3)!);
      }
    }
  } catch (e) {
    throw (Exception('$T could not be decoded from data'));
  }
  return {};
}