buildFilesList method

Widget buildFilesList(
  1. GenericUploadController controller
)

Implementation

Widget buildFilesList(GenericUploadController controller) {
  return Obx(() {
    return Wrap(
      spacing: 10,
      runSpacing: 10,
      children: controller.files.map((file) {
        final url = file.funRefVal ?? '';
        final fileName = Uri.parse(url).pathSegments.isNotEmpty
            ? Uri.parse(url).pathSegments.last
            : url; // fallback to full url if parsing fails

        return InkWell(
          onTap: () async {
            // open the file in browser or download
            if (await canLaunchUrl(Uri.parse(url))) {
              await launchUrl(Uri.parse(url),
                  mode: LaunchMode.externalApplication);
            }
          },
          child: Container(
            width: 160,
            padding: const EdgeInsets.all(12),
            decoration: BoxDecoration(
              color: Colors.grey.shade50,
              borderRadius: BorderRadius.circular(12),
              border: Border.all(color: Colors.grey.shade300),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              spacing: 5,
              children: [
                Stack(
                  children: [
                    const Align(
                      alignment: Alignment.center,
                      child: Icon(Icons.insert_drive_file_outlined,
                          size: 50, color: Colors.blueGrey),
                    ),
                    if (!controller.isViewScreen.value)
                      Positioned(
                        right: -5,
                        top: -5,
                        child: InkWell(
                          onTap: () => controller.deleteFile(file),
                          child: const Icon(Icons.delete, color: Colors.red),
                        ),
                      ),
                  ],
                ),
                Column(
                  children: [
                    AppText(
                      fileName,
                      style: TextStyles.small(Get.context!),
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                    AppText(
                      '${file.createdOn != null ? AppDateUtils.toDayMonthYear(DateTime.parse(file.createdOn.toString())).trim() : AppDateUtils.toDayMonthYear(DateTime.now())}  ${file.userDisplayName != null ? file.userDisplayName?.trim() : '(ME)'}',
                      style: TextStyles.normalBold(Get.context!),
                      maxLines: 5,
                      softWrap: true,
                    ),
                  ],
                ),
              ],
            ),
          ),
        );
      }).toList(),
    );
  });
}