deserializeParam<T> function
Implementation
dynamic deserializeParam<T>(
String? param,
ParamType paramType,
bool isList,
) {
try {
if (param == null) {
return null;
}
if (isList) {
final paramValues = json.decode(param);
if (paramValues is! Iterable || paramValues.isEmpty) {
return null;
}
return paramValues
.whereType<String>()
.map((p) => p)
.map((p) => deserializeParam<T>(p, paramType, false))
.where((p) => p != null)
.map((p) => p! as T)
.toList();
}
switch (paramType) {
case ParamType.int:
return int.tryParse(param);
case ParamType.double:
return double.tryParse(param);
case ParamType.String:
return param;
case ParamType.bool:
return param == 'true';
case ParamType.DateTime:
final milliseconds = int.tryParse(param);
return milliseconds != null
? DateTime.fromMillisecondsSinceEpoch(milliseconds)
: null;
case ParamType.DateTimeRange:
return dateTimeRangeFromString(param);
case ParamType.LatLng:
return latLngFromString(param);
case ParamType.Color:
return fromCssColor(param);
case ParamType.FFPlace:
return placeFromString(param);
case ParamType.FFUploadedFile:
return uploadedFileFromString(param);
case ParamType.JSON:
return json.decode(param);
default:
return null;
}
} catch (e) {
print('Error deserializing parameter: $e');
return null;
}
}