toJson method

Map<String, dynamic> toJson()

Implementation

Map<String, dynamic> toJson() {
  final num? numberValue = num.tryParse(value.asUcumDecimal());
  if (numberValue != null) {
    return <String, dynamic>{
      'value': numberValue,
      'code': unit,
    };
  } else {
    final BigInt? bigIntValue = BigInt.tryParse(value.asUcumDecimal());
    if (bigIntValue != null) {
      return <String, dynamic>{
        'value': bigIntValue,
        'code': unit,
      };
    }
  }
  return <String, dynamic>{
    'value': value,
    'code': unit,
  };
}