import 'dart:typed_data'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:get_thumbnail_video/index.dart'; import 'package:get_thumbnail_video/video_thumbnail.dart'; import 'package:onufitness/constants/color_constant.dart'; import 'package:onufitness/constants/text_constant.dart'; import 'package:onufitness/screens/u_vault/controllers/uvault_video_controller.dart'; import 'package:onufitness/utils/helper_function.dart'; import 'package:onufitness/widgets/Buttons/custom_submit_button.dart'; class DraftVideosScreen extends StatelessWidget { DraftVideosScreen({super.key}); final UvaultController controller = Get.put(UvaultController()); @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( elevation: 0, backgroundColor: Colors.white, leading: IconButton( icon: Icon(Icons.arrow_back_ios, color: Colors.black), onPressed: () => Get.back(), ), title: Text( "Draft Videos", style: TextStyle( fontSize: appBarHeardingText, fontWeight: FontWeight.w600, color: Colors.black, ), ), ), body: Obx(() { final draftVideos = controller.draftVideos; if (controller.seeMoreList.length != draftVideos.length) { controller.initializeSeeMoreList(draftVideos.length); } if (draftVideos.isEmpty) { return Center( child: Text( "No draft videos found", style: TextStyle( fontSize: 16.sp, color: greyTextColor1, fontWeight: FontWeight.w500, ), ), ); } return ListView.builder( padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), itemCount: draftVideos.length, itemBuilder: (context, index) { final item = draftVideos[index]; return Container( margin: EdgeInsets.only(bottom: 16.h), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ FutureBuilder( future: VideoThumbnail.thumbnailData( video: item.videoFilePath, imageFormat: ImageFormat.JPEG, maxWidth: 128, quality: 75, ), builder: (context, snapshot) { if (snapshot.hasData && snapshot.data != null) { return ClipRRect( borderRadius: BorderRadius.circular(10.r), child: Image.memory( snapshot.data!, width: isTablet ? 150.w : 120.w, height: isTablet ? 120.h : 100.h, fit: BoxFit.cover, ), ); } else { return Container( width: 120.w, height: 100.h, decoration: BoxDecoration( color: greyTextColor1, borderRadius: BorderRadius.circular(12.r), ), child: Icon( Icons.broken_image, color: greyTextColor1, ), ); } }, ), SizedBox(width: 12.w), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Text( 'Upload failed', style: TextStyle( fontSize: verySmallSizeText, color: Colors.red, fontWeight: FontWeight.w500, ), ), Spacer(), Text( item.failedDate, style: TextStyle( fontSize: verySmallSizeText, color: greyTextColor1, ), ), ], ), SizedBox(height: 4.h), Obx(() { final isExpanded = controller.seeMoreList[index]; final titleText = item.title; final needsSeeMore = titleText.length > 50; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( titleText, maxLines: isExpanded ? null : 2, overflow: isExpanded ? TextOverflow.visible : TextOverflow.ellipsis, style: TextStyle( fontSize: isTablet ? verySmallSizeText : smallSizeText, color: Colors.black, ), ), if (needsSeeMore) Padding( padding: EdgeInsets.only(top: 4.h), child: GestureDetector( onTap: () { controller.toggleSeeMore(index); }, child: Text( isExpanded ? 'See less' : 'See more', style: TextStyle( fontSize: smallSizeText, color: Colors.blue, ), ), ), ), ], ); }), SizedBox(height: 8.h), Row( children: [ CustomSubmitButton( width: isTablet ? 100.w : 80.w, height: 30.h, backgroundColor: Colors.black, textStyle: TextStyle( fontSize: isTablet ? 12.sp : 14.sp, color: Colors.white, ), text: "Delete", onPressed: () { controller.deleteDraftVideo(index); controller.loadDraftVideos(); }, ), SizedBox(width: 8.w), Obx( () => CustomSubmitButton( width: isTablet ? 100.w : 80.w, height: 30.h, backgroundColor: Color(primaryColor), textColor: Colors.black, text: "Retry", textStyle: TextStyle( fontSize: isTablet ? 12.sp : 14.sp, color: Colors.black, ), isLoading: controller.uploadingIndexes.contains( index, ), onPressed: () async { controller.draftVideoIndex = index; controller.setUploading(true); final failedUpload = controller.draftVideos[index]; controller.selectedFitnessGoalId.value = failedUpload.fitnessGoalId; controller.videoTitleController.text = failedUpload.title; if (failedUpload.videoFilePath.isNotEmpty) { controller .selectedFile .value = PlatformFile( name: failedUpload.title, size: 0, path: failedUpload.videoFilePath, ); } await controller.uploadFileToAPI().then(( value, ) { if (value == true) { controller.deleteDraftVideo(index); controller.loadDraftVideos(); } }); controller.setUploading(false); }, ), ), ], ), ], ), ), ], ), ); }, ); }), ); } }