copyWithType method
Get a copy of a record with a specific type
Accepted types: String, int, double, bool and Uint8List
Implementation
DbRecord? copyWithType(Type t) {
switch (t) {
case String:
return DbRecord<String>(key, value.toString());
break;
case int:
try {
final v = int.parse(value.toString());
return DbRecord<int>(key, v);
} catch (e) {
throw Exception("Can not convert $value to $t "
"for key $key");
}
break;
case double:
try {
final v = double.parse(value.toString());
return DbRecord<double>(key, v);
} catch (e) {
throw Exception("Can not convert $value to $t "
"for key $key");
}
break;
case bool:
final dynamic val = value.toString();
if (val == "true") {
return DbRecord<bool>(key, true);
} else if (val == "false") {
return DbRecord<bool>(key, false);
} else {
throw Exception("Can not convert $value to $t "
"for key $key");
}
break;
case Uint8List:
try {
final v = value as Uint8List;
return DbRecord<Uint8List>(key, v);
} catch (e) {
throw Exception("Can not convert $value to $t "
"for key $key");
}
break;
}
return null;
}