valueAsBigInt<T extends BigInt?> static method
T
valueAsBigInt<
T extends BigInt?>( - Object? value, {
- bool allowHex = false,
- bool? sign,
})
Implementation
static T valueAsBigInt<T extends BigInt?>(
Object? value, {
bool allowHex = false,
bool? sign,
}) {
final v = (() {
if (value is T) {
return value;
}
if (value == null && _isNull<T>()) return null as T;
final toBigint = BigintUtils.tryParse(value, allowHex: allowHex);
if (toBigint == null) {
throw JsonParserError("Failed to parse value as bigint.");
}
return toBigint as T;
}());
if (v == null) return v;
if (sign != null && !sign && v.isNegative) {
throw JsonParserError(
"Invalid unsigned bigint.",
details: {"value": v.toString()},
);
}
return v;
}