Преглед на файлове

show free space in MBs if free space is less than 100MB

ashilkn преди 2 години
родител
ревизия
9c2e645aeb
променени са 2 файла, в които са добавени 30 реда и са изтрити 8 реда
  1. 25 8
      lib/ui/settings/details_section_widget.dart
  2. 5 0
      lib/utils/data_util.dart

+ 25 - 8
lib/ui/settings/details_section_widget.dart

@@ -111,6 +111,15 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
   }
 
   Widget userDetails(UserDetails userDetails) {
+    bool shouldShowFreeSpaceInMBs = false;
+
+    const hundredMBinBytes = 107374182;
+    final freeSpaceInBytes = userDetails.getFreeStorage();
+
+    if (freeSpaceInBytes < hundredMBinBytes) {
+      shouldShowFreeSpaceInMBs = true;
+    }
+
     final usedSpaceInGB =
         convertBytesToGB(userDetails.getFamilyOrPersonalUsage());
     final totalStorageInGB = convertBytesToGB(userDetails.getTotalStorage());
@@ -267,14 +276,22 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
                           ),
                     Column(
                       children: [
-                        Text(
-                          "${_roundedFreeSpace(totalStorageInGB, usedSpaceInGB)} GB free",
-                          style:
-                              Theme.of(context).textTheme.bodyText1!.copyWith(
-                                    color: Colors.white,
-                                    fontSize: 12,
-                                  ),
-                        ),
+                        RichText(
+                          text: TextSpan(
+                            text:
+                                "${shouldShowFreeSpaceInMBs ? convertBytesToMB(freeSpaceInBytes) : _roundedFreeSpace(totalStorageInGB, usedSpaceInGB)}",
+                            style: getEnteTextTheme(context)
+                                .mini
+                                .copyWith(color: textFaintDark),
+                            children: [
+                              TextSpan(
+                                text: shouldShowFreeSpaceInMBs
+                                    ? " MB free"
+                                    : " GB free",
+                              )
+                            ],
+                          ),
+                        )
                       ],
                     ),
                   ],

+ 5 - 0
lib/utils/data_util.dart

@@ -25,6 +25,7 @@ String formatBytes(int bytes, [int decimals = 2]) {
   return ((bytes / pow(k, i)).toStringAsFixed(dm)) + ' ' + storageUnits[i];
 }
 
+//shows decimals only if less than 10GB & omits decimal if decimal is 0
 num convertBytesToGB(int bytes) {
   const tenGBinBytes = 10737418240;
   int precision = 0;
@@ -35,3 +36,7 @@ num convertBytesToGB(int bytes) {
       num.parse((bytes / (pow(1024, 3))).toStringAsPrecision(precision));
   return bytesInGB;
 }
+
+int convertBytesToMB(int bytes) {
+  return (bytes / pow(1024, 2)).round();
+}