analysis_state.dart 820 B

12345678910111213141516171819202122232425262728
  1. // 创建一个共享状态类
  2. import 'package:get/get_rx/src/rx_types/rx_types.dart';
  3. import 'package:intl/intl.dart';
  4. import '../../model/asset_info.dart';
  5. class AnalysisState {
  6. static RxList<AssetInfo> imageList = <AssetInfo>[].obs;
  7. static RxMap<String, List<AssetInfo>> assetsByMonth = <String, List<AssetInfo>>{}.obs;
  8. // 删除图片
  9. static void removeAsset(String assetId) {
  10. imageList.removeWhere((asset) => asset.id == assetId);
  11. updateMonthlyAssets();
  12. }
  13. // 更新月份分组
  14. static void updateMonthlyAssets() {
  15. assetsByMonth.clear();
  16. for (var asset in imageList) {
  17. final month = DateFormat('yyyy-MM').format(asset.createDateTime);
  18. if (!assetsByMonth.containsKey(month)) {
  19. assetsByMonth[month] = [];
  20. }
  21. assetsByMonth[month]!.add(asset);
  22. }
  23. }
  24. }