优化formatBytes函数
This commit is contained in:
parent
7bc09696af
commit
4b3034587c
|
|
@ -1006,7 +1006,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
||||||
context,
|
context,
|
||||||
icon: Icons.file_download,
|
icon: Icons.file_download,
|
||||||
label: '新版体积',
|
label: '新版体积',
|
||||||
value: formatBytes(info.apkSize!),
|
value: UpgradeUtils.formatBytes(info.apkSize!),
|
||||||
colorScheme: colorScheme,
|
colorScheme: colorScheme,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
String formatBytes(int bytes) {
|
class UpgradeUtils {
|
||||||
if (bytes < 1024) return '$bytes B';
|
static String formatBytes(int bytes) {
|
||||||
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(2)} KB';
|
if (bytes < 1024) return '$bytes B';
|
||||||
if (bytes < 1024 * 1024 * 1024) {
|
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(2)} KB';
|
||||||
return '${(bytes / (1024 * 1024)).toStringAsFixed(2)} MB';
|
if (bytes < 1024 * 1024 * 1024) {
|
||||||
|
return '${(bytes / (1024 * 1024)).toStringAsFixed(2)} MB';
|
||||||
|
}
|
||||||
|
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB';
|
||||||
}
|
}
|
||||||
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB';
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue