| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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<AssetInfo> imageList = <AssetInfo>[].obs;
- // 当前显示的图片索引
- final RxInt currentImageIndex = 0.obs;
- @override
- void onInit() {
- // TODO: implement onInit
- super.onInit();
- if (Get.arguments != null) {
- final args = Get.arguments as Map<String, dynamic>;
- imageList.value = Get.arguments["list"] as List<AssetInfo>;
- 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: <Widget>[
- //操作按钮集合
- 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]})";
- }
- }
- }
|