mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
22
lib/util/size_formatting.dart
Normal file
22
lib/util/size_formatting.dart
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
extension IntExtension on int? {
|
||||
String? get byteFormat {
|
||||
final bytes = this;
|
||||
if (bytes == null) return null;
|
||||
if (bytes == 0) return "- bytes";
|
||||
const int KB = 1024;
|
||||
const int MB = KB * KB;
|
||||
const int GB = MB * KB;
|
||||
|
||||
if (bytes >= GB) {
|
||||
return '${(bytes / GB).toStringAsFixed(2)} GB';
|
||||
} else if (bytes >= MB) {
|
||||
return '${(bytes / MB).toStringAsFixed(2)} MB';
|
||||
} else if (bytes >= KB) {
|
||||
return '${(bytes / KB).toStringAsFixed(2)} KB';
|
||||
} else {
|
||||
return '$bytes Bytes';
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue