locations_photo_controller.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import 'dart:io';
  2. import 'package:clean/module/image_picker/image_picker_util.dart';
  3. import 'package:clean/module/locations_photo/locations_single_photo_view.dart';
  4. import 'package:clean/module/people_photo/photo_group.dart';
  5. import 'package:get/get.dart';
  6. import 'package:path_provider/path_provider.dart';
  7. import 'package:path/path.dart' as p;
  8. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  9. class LocationsPhotoController extends GetxController {
  10. final RxList<PhotoGroup> photoGroups = <PhotoGroup>[].obs;
  11. @override
  12. onInit() {
  13. super.onInit();
  14. loadLocationPhoto();
  15. }
  16. void loadLocationPhoto() {
  17. photoGroups.clear();
  18. RxMap<String, List<AssetEntity>> locationPhotos =
  19. ImagePickerUtil.locationPhotos;
  20. if (locationPhotos.isNotEmpty) {
  21. for (var entry in locationPhotos.entries) {
  22. photoGroups.add(PhotoGroup(
  23. title: 'photo: ${entry.value.length}',
  24. imageCount: entry.value.length,
  25. isSelected: false,
  26. images: entry.value,
  27. location: entry.key,
  28. ));
  29. }
  30. }
  31. }
  32. void clickPhotoGroup(PhotoGroup photoGroup) {
  33. print('clickPhotoGroup ${photoGroup.location}');
  34. LocationsSinglePhotoPage.start(photoGroup: photoGroup);
  35. }
  36. PhotoGroup getGroupByLocation(String? location) {
  37. return photoGroups.firstWhere((group) => group.location == location);
  38. }
  39. // PhotoGroup getGroupByImages(List<AssetEntity> images) {
  40. // final imageIds = images.map((img) => img.id).toSet();
  41. // return photoGroups.firstWhere((group) =>
  42. // group.images.every((image) => imageIds.contains(image.id))
  43. // );
  44. // }
  45. }