Ver Fonte

[fix]修改首页容量显示

Destiny há 1 ano atrás
pai
commit
e90b821fe4
2 ficheiros alterados com 16 adições e 6 exclusões
  1. 15 5
      lib/module/home/home_controller.dart
  2. 1 1
      lib/module/home/home_view.dart

+ 15 - 5
lib/module/home/home_controller.dart

@@ -23,6 +23,11 @@ class HomeController extends BaseController {
   Rx<double> photoSpace = 100.0.obs;
   Rx<double> freeSpace = 200.0.obs;
 
+  Rx<String> totalSpaceStr = "".obs;
+  Rx<String> usedSpaceStr = "".obs;
+  Rx<String> photoSpaceStr = "".obs;
+  Rx<String> freeSpaceStr = "".obs;
+
   // 计算已用存储百分比
   double get usedSpacePercentage => (usedSpace.value / totalSpace.value) * 100;
 
@@ -90,8 +95,8 @@ class HomeController extends BaseController {
         print('Error loading photos: $e');
       }
     }
-
   }
+
   Future<void> getStorageInfo() async {
 
     final classifyPhoto = ClassifyPhoto();
@@ -105,15 +110,20 @@ class HomeController extends BaseController {
       final usedSpaceGB = storageInfo['usedSpace']! / (1024 * 1024 * 1024);
       final photoSpaceGB = storageInfo['photoSpace']! / (1024 * 1024 * 1024);
 
+      totalSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['totalSpace']!, decimals: 1);
+      freeSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['freeSpace']!, decimals: 1);
+      usedSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['usedSpace']!, decimals: 1);
+      photoSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['photoSpace']!, decimals: 1);
+
       totalSpace.value = totalSpaceGB.round().toDouble();
       freeSpace.value = freeSpaceGB;
       usedSpace.value = usedSpaceGB;
       photoSpace.value = photoSpaceGB;
 
-      print('总容量: ${totalSpaceGB.toStringAsFixed(0)} GB');
-      print('可用空间: ${freeSpaceGB.toStringAsFixed(2)} GB');
-      print('已用空间: ${usedSpaceGB.toStringAsFixed(2)} GB');
-      print('照片占用: ${photoSpaceGB.toStringAsFixed(2)} GB');
+      print('总容量: $totalSpaceStr');
+      print('可用空间: $freeSpaceStr');
+      print('已用空间: $usedSpaceStr');
+      print('照片占用: $photoSpaceStr');
 
     } catch (e) {
       print('获取存储信息失败: $e');

+ 1 - 1
lib/module/home/home_view.dart

@@ -312,7 +312,7 @@ class HomePage extends BaseView<HomeController> {
                 ),
                 Obx(() {
                   return Text(
-                    '${controller.photoSpace.toStringAsFixed(1)} GB',
+                    '${controller.photoSpaceStr}',
                     textAlign: TextAlign.start,
                     style: TextStyle(
                       color: Colors.white.withValues(alpha: 0.6499999761581421),