toString method

  1. @override
String toString([
  1. String symbol = 'KB',
  2. int precision = 2,
  3. String locale_LANG = 'en_US'
])
override

Returns the string representation of the ByteSize instance i.e passing the symbol, precision and or locale_LANG as arguments.

var size = ByteSize.FromKiloBytes(10000);
print(size.ToString('MB', 1, Locale.fr_CA)); // 9,8 MB

Implementation

@override
String toString(
    [String symbol = 'KB', int precision = 2, String locale_LANG = 'en_US']) {
  symbol = symbol.replaceAll(' ', '');

  if (symbol.contains('PB')) {
    return '${_Output(PetaBytes, precision, locale_LANG)} $symbol';
  } else if (symbol.contains('TB')) {
    return '${_Output(TeraBytes, precision, locale_LANG)} $symbol';
  } else if (symbol.contains('GB')) {
    return '${_Output(GigaBytes, precision, locale_LANG)} $symbol';
  } else if (symbol.contains('MB')) {
    return '${_Output(MegaBytes, precision, locale_LANG)} $symbol';
  } else if (symbol.contains('KB')) {
    return '${_Output(KiloBytes, precision, locale_LANG)} $symbol';
  } else if (symbol.contains(_ByteSymbol)) {
    return '${_Output(Bytes, precision, locale_LANG)} $symbol';
  } else if (symbol.contains(_BitSymbol)) {
    return '${_Output(Bits.toDouble(), precision, locale_LANG)} $symbol';
  }
  return '${_Output(_largestWholeNumberValue(), precision, locale_LANG)} ${_largestWholeNumberSymbol()}';
}