importJson method

Future<SavedRoomScan> importJson(
  1. String source
)

Imports JSON created by exportJson as a new library entry.

Output files are not embedded in JSON and therefore are not restored.

Implementation

Future<SavedRoomScan> importJson(String source) async {
  final decoded = jsonDecode(source);
  if (decoded is! Map<String, dynamic> ||
      decoded['formatVersion'] != _formatVersion ||
      decoded['scanResult'] is! Map<String, dynamic>) {
    throw const FormatException('Unsupported or invalid room scan JSON.');
  }
  final name = decoded['name']?.toString().trim() ?? '';
  if (name.isEmpty) throw const FormatException('The scan name is missing.');
  final scan = ScanResult.fromJson(
    Map<String, dynamic>.from(decoded['scanResult'] as Map),
  );
  return save(name: name, scanResult: scan);
}