buildPhotosTab method

Widget buildPhotosTab(
  1. GenericUploadController controller
)

Implementation

Widget buildPhotosTab(GenericUploadController controller) {
  return SingleChildScrollView(
    child: Column(
      children: [
        Column(
          children: [
            // File picker at the top
            if (!controller.isViewScreen.value)
              FilePickerWidget(
                icon: Icons.image_outlined,
                title: 'Click here to pick photos',
                onTap: controller.pickImages,
                appList: controller.images,
                onClearPressed: () => controller.clearSelectedImages(),
                showDeleteIcon: canDeleteAll,
              ),
            const SizedBox(height: 10),

            // Selected image container with zoom
            Obx(() {
              if (controller.selectedImage.value == null) {
                return const SizedBox(
                  height: 320,
                  child: Center(child: NoDataFound()),
                );
              }

              return Container(
                height: 320,
                width: double.infinity,
                color: Colors.black12,
                child: Image.network(
                  controller.selectedImage.value!.funRefVal ?? '',
                  fit: BoxFit.contain,
                  errorBuilder: (_, __, ___) =>
                      const Icon(Icons.broken_image, size: 50),
                ),
              );
            }),
            const SizedBox(height: 10),
            Obx(() {
              if (controller.selectedImage.value == null)
                return const SizedBox();
              return Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  IconButton(
                    icon: const Icon(Icons.zoom_in),
                    tooltip: 'Zoom In/Out',
                    onPressed: () {
                      Get.dialog(
                        zoomImage(controller),
                        barrierDismissible: false,
                      );
                    },
                  ),
                  IconButton(
                    icon: const Icon(Icons.download),
                    tooltip: 'Download',
                    onPressed: () {
                      _downloadImage(
                          controller.selectedImage.value!.funRefVal ?? '');
                    },
                  ),
                  if (!controller.isViewScreen.value)
                    IconButton(
                      icon: const Icon(Icons.delete),
                      tooltip: 'Delete',
                      onPressed: controller.deleteSelectedImage,
                    ),
                ],
              );
            }),

            const SizedBox(height: 10),

            // Thumbnails carousel with arrows
            SizedBox(
              height: 80,
              child: Row(
                children: [
                  if (controller.selectedImage.value != null)
                    IconButton(
                      icon: const Icon(Icons.arrow_back),
                      onPressed: () => controller.scrollThumbnails(-1),
                    ),
                  Expanded(
                    child: Obx(() {
                      return ListView.separated(
                        scrollDirection: Axis.horizontal,
                        controller: controller.thumbnailScrollController,
                        itemCount: controller.images.length,
                        separatorBuilder: (_, __) =>
                            const SizedBox(width: 10),
                        itemBuilder: (context, index) {
                          final image = controller.images[index];
                          return GestureDetector(
                            onTap: () {
                              controller.selectedImage.value = image;
                            },
                            child: Container(
                              width: 80,
                              decoration: BoxDecoration(
                                border: Border.all(
                                  color: Colors.red,
                                  width: 2,
                                ),
                                borderRadius: BorderRadius.circular(8),
                              ),
                              child: ClipRRect(
                                borderRadius: BorderRadius.circular(6),
                                child: Image.network(
                                  image.funRefVal ?? '',
                                  fit: BoxFit.cover,
                                  errorBuilder: (_, __, ___) =>
                                      const Icon(Icons.broken_image),
                                ),
                              ),
                            ),
                          );
                        },
                      );
                    }),
                  ),
                  if (controller.selectedImage.value != null)
                    IconButton(
                      icon: const Icon(Icons.arrow_forward),
                      onPressed: () => controller.scrollThumbnails(1),
                    ),
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 10),
        // Save button
        Row(
          spacing: 10,
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            buildSaveAttachmentButton(controller),
            AppButton(
                isCancelButton: true,
                onPressed: () {
                  if (!controller.isEditScreen.value) {
                    controller.clearMedia();
                  }
                  Get.back();
                },
                text: 'Close')
          ],
        ),
      ],
    ),
  );
}