Anchor.valueOf constructor

Anchor.valueOf(
  1. String name
)

This should only be used for de-serialization purposes.

If you need to convert anchors to serializable data (like JSON), use the toString() and valueOf methods.

Implementation

factory Anchor.valueOf(String name) {
  if (_valueNames.containsValue(name)) {
    return _valueNames.entries.singleWhere((e) => e.value == name).key;
  } else {
    final regexp = RegExp(r'^\Anchor\(([^,]+), ([^\)]+)\)');
    final matches = regexp.firstMatch(name)?.groups([1, 2]);
    assert(
      matches != null && matches.length == 2,
      'Bad anchor format: $name',
    );
    return Anchor(double.parse(matches![0]!), double.parse(matches[1]!));
  }
}