Procházet zdrojové kódy

地点照片二级页面

云天逵 před 1 rokem
rodič
revize
22b0f75642

+ 23 - 1
lib/module/locations_photo/locations_photo_controller.dart

@@ -1,5 +1,6 @@
 import 'dart:io';
 
+import 'package:clean/module/image_picker/image_picker_util.dart';
 import 'package:clean/module/people_photo/photo_group.dart';
 import 'package:get/get.dart';
 import 'package:path_provider/path_provider.dart';
@@ -10,7 +11,8 @@ class LocationsPhotoController extends GetxController {
   @override
   onInit() {
     super.onInit();
-    loadPhotosFromDirectory();
+    loadLocationPhoto();
+    // loadPhotosFromDirectory();
   }
 
   Future<void> loadPhotosFromDirectory() async {
@@ -24,6 +26,7 @@ class LocationsPhotoController extends GetxController {
           imageCount: result.length,
           isSelected: false,
           images: result,
+          location: "测试".obs,
         ));
       }
     } catch (e) {
@@ -31,4 +34,23 @@ class LocationsPhotoController extends GetxController {
     }
   }
 
+  void loadLocationPhoto() {
+    photoGroups.clear();
+
+    RxMap<String, List<AssetEntity>> locationPhotos = ImagePickerUtil.locationPhotos;
+
+    if (locationPhotos.isNotEmpty) {
+      for (var entry in locationPhotos.entries) {
+
+        photoGroups.add(PhotoGroup(
+          title: 'photo: ${entry.value.length}',
+          imageCount: entry.value.length,
+          isSelected: false,
+          images: entry.value,
+          location: entry.key.obs,
+        ));
+      }
+    }
+  }
+
 }

+ 25 - 26
lib/module/locations_photo/locations_photo_view.dart

@@ -34,14 +34,14 @@ class LocationsPhotoPage extends BasePage<LocationsPhotoController> {
                     padding: EdgeInsets.symmetric(horizontal: 16.w),
                     children: [
                       ...controller.photoGroups.map((group) => Column(
-                        children: [
-                          _buildPhotoGroup(
-                            title: group.title,
-                            imageCount: group.imageCount,
-                          ),
-                          SizedBox(height: 15.h),
-                        ],
-                      ))
+                            children: [
+                              _buildPhotoGroup(
+                                title: group.title,
+                                imageCount: group.imageCount,
+                              ),
+                              SizedBox(height: 15.h),
+                            ],
+                          ))
                     ],
                   );
                 }),
@@ -58,6 +58,7 @@ class LocationsPhotoPage extends BasePage<LocationsPhotoController> {
       ),
     ]);
   }
+
   Widget _titleCard() {
     return Container(
       alignment: Alignment.centerLeft,
@@ -119,13 +120,15 @@ class LocationsPhotoPage extends BasePage<LocationsPhotoController> {
               ),
             ],
           ),
-          SizedBox(child:
-            GestureDetector(
+          SizedBox(
+            child: GestureDetector(
               // onTap: () => controller.toggleImageSelection(title, 0),
               child: Obx(() {
-                final group = controller.photoGroups
-                    .firstWhere((g) => g.title == title);
+                final group =
+                    controller.photoGroups.firstWhere((g) => g.title == title);
                 final imagePath = group.images[0];
+                final location = group.location?.value?? '';
+
                 return Stack(
                   children: [
                     Container(
@@ -137,32 +140,28 @@ class LocationsPhotoPage extends BasePage<LocationsPhotoController> {
                           borderRadius: BorderRadius.circular(8.r),
                         ),
                         image: DecorationImage(
-                          image:
-                          AssetEntityImageProvider(imagePath),
+                          image: AssetEntityImageProvider(imagePath),
                           fit: BoxFit.cover,
                         ),
                       ),
                     ),
-
-
                     Positioned(
                         left: 1.w,
                         right: 1.w,
                         bottom: 16.sp,
-                        child:Text(
-                      'Beijing',
-                      textAlign: TextAlign.center,
-                      style: TextStyle(
-                        color: Colors.white,
-                        fontSize: 20.sp,
-                        fontWeight: FontWeight.w500,
-                      ),
-                    ))
+                        child: Text(
+                          location,
+                          textAlign: TextAlign.center,
+                          style: TextStyle(
+                            color: Colors.white,
+                            fontSize: 20.sp,
+                            fontWeight: FontWeight.w500,
+                          ),
+                        ))
                   ],
                 );
               }),
             ),
-
           ),
         ],
       ),

+ 3 - 5
lib/module/people_photo/people_photo_controller.dart

@@ -48,7 +48,7 @@ class PeoplePhotoController extends GetxController {
   @override
   void onInit() {
     super.onInit();
-    loadSimilarPhotos();
+    loadPeoplePhoto();
       if (_hasInitializedSelections) {
         _restoreSelections();
       }
@@ -94,11 +94,9 @@ class PeoplePhotoController extends GetxController {
     }
   }
 
-  void loadSimilarPhotos() {
-    // 清空现有数据
-    photoGroups.clear();
+  void loadPeoplePhoto() {
 
-    // 将 ImagePickerUtil 中的相似照片转换为 PhotoGroup
+    photoGroups.clear();
 
       final photoGroup = ImagePickerUtil.peoplePhotos;
       if (photoGroup.isNotEmpty) {

+ 7 - 1
lib/module/people_photo/photo_group.dart

@@ -2,17 +2,22 @@ import 'package:get/get.dart';
 import 'package:wechat_assets_picker/wechat_assets_picker.dart';
 
 class PhotoGroup {
-
   final String title;
+
   //照片组的总数。
   final int imageCount;
+
   // 照片组是否被全选中
   final RxBool isSelected;
+
   // 照片组的列表。
   final List<AssetEntity> images;
+
   //单个照片是否被选中
   final RxList<bool> selectedImages;
 
+  final RxString? location;
+
   // 选中的照片数量
   int get selectedCount => selectedImages.where((selected) => selected).length;
 
@@ -21,6 +26,7 @@ class PhotoGroup {
     required this.imageCount,
     required bool isSelected,
     required this.images,
+    this.location,
   })  : isSelected = isSelected.obs,
         selectedImages = List.generate(imageCount, (_) => isSelected).obs;