TextBlock.fromJson constructor

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

Implementation

factory TextBlock.fromJson(Map<String, dynamic> json) {
  Rect? box;
  if (json['boundingBox'] != null && json['boundingBox'] is Map) {
    final b = json['boundingBox'] as Map<String, dynamic>;
    box = Rect.fromLTWH(
      (b['left'] as num).toDouble(),
      (b['top'] as num).toDouble(),
      (b['width'] as num).toDouble(),
      (b['height'] as num).toDouble(),
    );
  }
  List<TextLine> lns = [];
  if (json['lines'] != null && json['lines'] is List) {
    lns = (json['lines'] as List)
        .map((l) => TextLine.fromJson(l as Map<String, dynamic>))
        .toList();
  }
  return TextBlock(
    text: json['text'] as String? ?? '',
    lines: lns,
    boundingBox: box,
    confidence: (json['confidence'] as num?)?.toDouble() ?? 1.0,
    recognizedLanguage: json['recognizedLanguage'] as String?,
  );
}