Files
lunasea/lib/core/extensions/integer/bytes.dart
Jagandeep Brar 6b60fda2fa [TestFlight] v4.0.0+400001 (#240)
NEW
- [Tautulli] View Activity
- [Tautulli] View activity details
- [Tautulli] View list of users
- [Tautulli] Ability to backup configuration & database
- [Tautulli] Ability to delete cache & image cache
- [Drawer] Ability to set the initial expanded state of categories (automation, clients, & monitoring)

TWEAKS
- [UI/Loader] New loading indicator
- [Home/Calendar] Separate calendar view type into its own preference
- [Home/Calendar] Show no modules enabled message when there are no automation modules enabled, not just no modules overall

FIXES
- [Profiles] Safeguarded fetching of enabled module
2020-08-24 04:06:00 -05:00

24 lines
1.3 KiB
Dart

import 'package:lunasea/core/constants.dart';
extension IntegerBytesExtension on int {
String _bytesToString({ int decimals = 2, position = 0, bool bytes = true }) {
if(this == null || this <= 0) return '${0.toStringAsFixed(decimals)} B';
int chunk = bytes ? 1024 : 1000;
double size = this.toDouble();
while(size > chunk) {
size /= chunk;
position++;
}
return '${size.toStringAsFixed(decimals)} ${bytes ? Constants.BYTE_SIZES[position] : Constants.BIT_SIZES[position]}';
}
// ignore: non_constant_identifier_names
String lsBytes_BytesToString({ int decimals = 2, bool bytes = true }) => _bytesToString(decimals: decimals, position: 0, bytes: bytes);
// ignore: non_constant_identifier_names
String lsBytes_KilobytesToString({ int decimals = 2, bool bytes = true }) => _bytesToString(decimals: decimals, position: 1, bytes: bytes);
// ignore: non_constant_identifier_names
String lsBytes_MegabytesToString({ int decimals = 2, bool bytes = true }) => _bytesToString(decimals: decimals, position: 2, bytes: bytes);
// ignore: non_constant_identifier_names
String lsBytes_GigabytesToString({ int decimals = 2, bool bytes = true }) => _bytesToString(decimals: decimals, position: 3, bytes: bytes);
}