TextBlock.fromMap constructor

TextBlock.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory TextBlock.fromMap(Map<String, dynamic> map) {
  Rect? box;
  if (map['boundingBox'] is Map) {
    final b = Map<String, dynamic>.from(map['boundingBox']);
    box = Rect.fromLTRB(
      (b['left'] as num).toDouble(),
      (b['top'] as num).toDouble(),
      (b['right'] as num).toDouble(),
      (b['bottom'] as num).toDouble(),
    );
  }

  final rawLines = (map['lines'] as List?) ?? [];
  final linesList = rawLines
      .whereType<Map>()
      .map((l) => TextLine.fromMap(Map<String, dynamic>.from(l)))
      .toList();

  return TextBlock(
    text: map['text']?.toString() ?? '',
    lines: linesList,
    boundingBox: box,
  );
}