CameraCutoutPathCommand.fromMap constructor

CameraCutoutPathCommand.fromMap(
  1. Object? value
)

Implementation

factory CameraCutoutPathCommand.fromMap(Object? value) {
  final Map<String, Object?> map = readMap(value);
  final CameraCutoutPathOperation operation = CameraCutoutPathOperation.values
      .firstWhere(
        (CameraCutoutPathOperation item) => item.name == map['operation'],
        orElse: () => throw FormatException(
          'Unknown path operation: ${map['operation']}',
        ),
      );
  final List<Object?> coordinates = readList(
    map['points'] ?? const <Object?>[],
  );
  if (coordinates.length.isOdd) {
    throw const FormatException('Path coordinates must contain x/y pairs.');
  }
  final List<Offset> points = <Offset>[
    for (int index = 0; index < coordinates.length; index += 2)
      Offset(
        readDouble(coordinates[index]),
        readDouble(coordinates[index + 1]),
      ),
  ];
  return CameraCutoutPathCommand(operation: operation, points: points);
}