Safe parse h/w from public magicMetadata

This commit is contained in:
Neeraj Gupta
2024-09-23 11:42:15 +05:30
parent 6e209a68e2
commit ee1dbd7e84

View File

@@ -1,5 +1,6 @@
import "dart:convert";
import "package:flutter/cupertino.dart";
import 'package:photos/models/metadata/common_keys.dart';
const editTimeKey = 'editedTime';
@@ -88,8 +89,8 @@ class PubMagicMetadata {
editedName: map[editNameKey],
caption: map[captionKey],
uploaderName: map[uploaderNameKey],
w: map[widthKey],
h: map[heightKey],
w: safeParseInt(map[widthKey], widthKey),
h: safeParseInt(map[heightKey], heightKey),
lat: map[latKey],
long: map[longKey],
mvi: map[motionVideoIndexKey],
@@ -97,4 +98,12 @@ class PubMagicMetadata {
mediaType: map[mediaTypeKey],
);
}
static int? safeParseInt(dynamic value, String key) {
if (value == null) return null;
if (value is int) return value;
debugPrint("PubMagicMetadata key: $key Unexpected value: $value");
if (value is String) return int.tryParse(value);
return null;
}
}