import 'dart:math'; import 'package:clean/module/privacy/privacy_state.dart'; import 'package:clean/utils/expand.dart'; import 'package:clean/utils/file_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:wechat_assets_picker/wechat_assets_picker.dart'; import '../../base/base_controller.dart'; import '../../model/asset_info.dart'; class PhotoInfoController extends BaseController { RxBool isAnalysis = false.obs; // 存储所有图片,按月份分组 RxList imageList = [].obs; // 当前显示的图片索引 final RxInt currentImageIndex = 0.obs; @override void onInit() { // TODO: implement onInit super.onInit(); if (Get.arguments != null) { final args = Get.arguments as Map; imageList.value = Get.arguments["list"] as List; var type = Get.arguments["type"] as String; ; if (type == "privacy") { isAnalysis.value = false; } else { isAnalysis.value = true; } // 设置初始索引 if (args.containsKey('index')) { currentImageIndex.value = args['index'] as int; } } } // 切换到下一张图片 void nextImage() { if (currentImageIndex.value < imageList.length - 1) { currentImageIndex.value++; } } // 切换到上一张图片 void previousImage() { if (currentImageIndex.value > 0) { currentImageIndex.value--; } } void deleteBtnClick(AssetInfo asset, int index) { showCupertinoModalPopup( context: Get.context!, builder: (context) { return CupertinoActionSheet( title: Text( "The file will be deleted from the privacy space", style: TextStyle( color: "#6E6E6E".color, fontSize: 12.sp, fontWeight: FontWeight.w300, ), ), actions: [ //操作按钮集合 CupertinoActionSheetAction( onPressed: () { Navigator.pop(context); FileUtils.deleteAsset(asset.id.substring(0, 36)); if (!isAnalysis.value) { PrivacyState.removeAsset(asset.id); // 从列表中移除 imageList = PrivacyState.imageList; } // 如果没有图片了,返回上一页 if (imageList.isEmpty) { Get.back(); } else { if (currentImageIndex.value != 0) { currentImageIndex.value = imageList.length - 1; } } }, child: Text( 'Delete', style: TextStyle( color: "#FC4C4F".color, fontWeight: FontWeight.w500, fontSize: 16.sp, ), ), ), ], cancelButton: CupertinoActionSheetAction( //取消按钮 onPressed: () { Navigator.pop(context); }, child: Text( 'Cancel', style: TextStyle( color: "#007AFF".color, fontWeight: FontWeight.w500, fontSize: 16.sp, ), ), ), ); }, ); } // 格式化文件大小显示 String formatFileSize(int bytes) { if (bytes <= 0) return "Delete"; final units = ['B', 'KB', 'MB', 'GB']; int digitGroups = (log(bytes) / log(1024)).floor(); if (bytes == 0) { return "Delete"; } else { return "Delete(${(bytes / pow(1024, digitGroups)).toStringAsFixed(1)} ${units[digitGroups]})"; } } }