From 50869afdf8b219621a1da332632292a05c2d12d9 Mon Sep 17 00:00:00 2001 From: sonle Date: Wed, 20 Dec 2023 14:05:36 +0700 Subject: [PATCH] fix: resolve noted issues --- .../desktop_filter_history_widget.dart | 15 + .../notification/success_card.dart | 4 +- .../contact_new_version/contact_screen.dart | 15 +- .../widget/contacts_widget.dart | 2 +- .../widget/list_contact_widget.dart | 4 + .../widgets/filter_history_widget.dart | 15 + .../history/widgets/history_file_item.dart | 15 +- .../history/widgets/history_file_list.dart | 2 +- lib/screens/my_files/files_detail_screen.dart | 445 +++++++++--------- 9 files changed, 285 insertions(+), 232 deletions(-) diff --git a/lib/desktop_screens_new/history_screen/widgets/desktop_filter_history_widget.dart b/lib/desktop_screens_new/history_screen/widgets/desktop_filter_history_widget.dart index 88f8ad99..a47046ca 100644 --- a/lib/desktop_screens_new/history_screen/widgets/desktop_filter_history_widget.dart +++ b/lib/desktop_screens_new/history_screen/widgets/desktop_filter_history_widget.dart @@ -73,6 +73,21 @@ class _DesktopFilterHistoryWidgetState title: 'All File Types', isCheck: optionalHistoryTypes .every((element) => listFileType.contains(element)), + onTap: () { + if (optionalHistoryTypes + .every((element) => listFileType.contains(element))) { + listFileType.clear(); + } else { + optionalHistoryTypes.forEach( + (element) { + if (!listFileType.contains(element)) { + listFileType.add(element); + } + }, + ); + } + widget.onSelectedOptionalFilter?.call(listFileType); + }, ), ListView.separated( shrinkWrap: true, diff --git a/lib/desktop_screens_new/notification/success_card.dart b/lib/desktop_screens_new/notification/success_card.dart index e4c925d3..0f92d94e 100644 --- a/lib/desktop_screens_new/notification/success_card.dart +++ b/lib/desktop_screens_new/notification/success_card.dart @@ -10,6 +10,7 @@ import 'package:flutter/material.dart'; class SuccessCard extends StatelessWidget { final FileHistory fileHistory; + const SuccessCard({Key? key, required this.fileHistory}) : super(key: key); @override @@ -58,7 +59,8 @@ class SuccessCard extends StatelessWidget { ), ), TextSpan( - text: '${fileHistory.fileDetails?.files?.length} files', + text: + '${fileHistory.fileDetails?.files?.length} files(s)', style: TextStyle( fontSize: 15, color: Color(0xFF18A2EF), diff --git a/lib/screens/contact_new_version/contact_screen.dart b/lib/screens/contact_new_version/contact_screen.dart index c61a9a03..77ebae91 100644 --- a/lib/screens/contact_new_version/contact_screen.dart +++ b/lib/screens/contact_new_version/contact_screen.dart @@ -37,6 +37,7 @@ class _ContactScreenState extends State late GroupService _groupService; late TabController _tabController; late TextEditingController searchController; + bool isReloading = false; @override void initState() { @@ -130,7 +131,7 @@ class _ContactScreenState extends State Widget buildBody() { return Consumer(builder: (context, provider, child) { - return widget.isLoading + return isReloading ? ContactSkeletonLoadingWidget() : InkWell( highlightColor: Colors.transparent, @@ -207,6 +208,8 @@ class _ContactScreenState extends State contactsType: ListContactType.contact, trustedContacts: trustedProvider.trustedContacts, searchKeywords: searchController.text, + onRefresh: () => + setState(() => isReloading = !isReloading), onTapContact: (contact) async { final result = await Navigator.push( context, @@ -240,6 +243,8 @@ class _ContactScreenState extends State contactsType: ListContactType.trusted, trustedContacts: trustedProvider.trustedContacts, searchKeywords: searchController.text, + onRefresh: () => + setState(() => isReloading = !isReloading), onTapContact: (contact) async { await Navigator.push( context, @@ -257,6 +262,8 @@ class _ContactScreenState extends State ListContactWidget( contactsType: ListContactType.groups, searchKeywords: searchController.text, + onRefresh: () => + setState(() => isReloading = !isReloading), onTapGroup: (group) async { WidgetsBinding.instance .addPostFrameCallback((_) async { @@ -355,8 +362,14 @@ class _ContactScreenState extends State } Future reloadPage() async { + setState(() { + isReloading = true; + }); await Future.delayed(Duration(milliseconds: 500), () async { await _groupService.fetchGroupsAndContacts(); + setState(() { + isReloading = false; + }); contactProvider.notify(); }); } diff --git a/lib/screens/contact_new_version/widget/contacts_widget.dart b/lib/screens/contact_new_version/widget/contacts_widget.dart index 496f0b44..f59ce6e3 100644 --- a/lib/screens/contact_new_version/widget/contacts_widget.dart +++ b/lib/screens/contact_new_version/widget/contacts_widget.dart @@ -63,7 +63,7 @@ class _ContactsWidgetState extends State { }, child: ListView.builder( controller: widget.scrollController, - physics: const ClampingScrollPhysics(), + physics: const AlwaysScrollableScrollPhysics(), itemCount: 27, shrinkWrap: true, itemBuilder: (context, alphabetIndex) { diff --git a/lib/screens/contact_new_version/widget/list_contact_widget.dart b/lib/screens/contact_new_version/widget/list_contact_widget.dart index 64ee0e90..db30b949 100644 --- a/lib/screens/contact_new_version/widget/list_contact_widget.dart +++ b/lib/screens/contact_new_version/widget/list_contact_widget.dart @@ -20,6 +20,7 @@ class ListContactWidget extends StatefulWidget { final ListContactType? contactsType; final String searchKeywords; final Function()? onTapAddButton; + final Function()? onRefresh; const ListContactWidget({ Key? key, @@ -33,6 +34,7 @@ class ListContactWidget extends StatefulWidget { this.contactsType, this.searchKeywords = '', this.onTapAddButton, + this.onRefresh, }) : super(key: key); @override @@ -143,7 +145,9 @@ class _ListContactWidgetState extends State onTapGroup: widget.onTapGroup, onSelectContacts: widget.onSelectContacts, onRefresh: () async { + widget.onRefresh?.call(); await _groupService.fetchGroupsAndContacts(); + widget.onRefresh?.call(); }, contactPadding: EdgeInsets.only(left: 18, right: 28), selectedContacts: widget.selectedContacts, diff --git a/lib/screens/history/widgets/filter_history_widget.dart b/lib/screens/history/widgets/filter_history_widget.dart index afdfdd62..cce33d94 100644 --- a/lib/screens/history/widgets/filter_history_widget.dart +++ b/lib/screens/history/widgets/filter_history_widget.dart @@ -72,6 +72,21 @@ class _FilterHistoryWidgetState extends State { title: 'All File Types', isCheck: optionalHistoryTypes .every((element) => listFileType.contains(element)), + onTap: () { + if (optionalHistoryTypes + .every((element) => listFileType.contains(element))) { + listFileType.clear(); + } else { + optionalHistoryTypes.forEach( + (element) { + if (!listFileType.contains(element)) { + listFileType.add(element); + } + }, + ); + } + widget.onSelectedOptionalFilter?.call(listFileType); + }, ), ListView.separated( shrinkWrap: true, diff --git a/lib/screens/history/widgets/history_file_item.dart b/lib/screens/history/widgets/history_file_item.dart index 7c9e6a91..64700f48 100644 --- a/lib/screens/history/widgets/history_file_item.dart +++ b/lib/screens/history/widgets/history_file_item.dart @@ -641,15 +641,12 @@ class _HistoryFileItemState extends State { }) { return InkWell( onTap: onTap, - child: CommonUtilityFunctions() - .isFileDownloadAvailable(widget.fileTransfer!.date!) - ? SvgPicture.asset( - icon, - width: 32, - height: 32, - fit: BoxFit.cover, - ) - : SizedBox.shrink(), + child: SvgPicture.asset( + icon, + width: 32, + height: 32, + fit: BoxFit.cover, + ), ); } diff --git a/lib/screens/history/widgets/history_file_list.dart b/lib/screens/history/widgets/history_file_list.dart index ddb77682..b2beae71 100644 --- a/lib/screens/history/widgets/history_file_list.dart +++ b/lib/screens/history/widgets/history_file_list.dart @@ -110,7 +110,7 @@ class _HistoryFileListState extends State { color: ColorConstants.moreFilesBackgroundColor, ), child: Text( - isExpanded ? 'Show Less' : '${fileListLength - 2} More Files', + isExpanded ? 'Show Less' : '${fileListLength - 2} More File(s)', style: TextStyle( color: ColorConstants.orangeColor, fontSize: 11, diff --git a/lib/screens/my_files/files_detail_screen.dart b/lib/screens/my_files/files_detail_screen.dart index 792573f3..e52406dd 100644 --- a/lib/screens/my_files/files_detail_screen.dart +++ b/lib/screens/my_files/files_detail_screen.dart @@ -256,251 +256,258 @@ class _FilesDetailScreenState extends State { } Widget _buildListView(List files) { - return ListView.separated( - shrinkWrap: true, - padding: EdgeInsets.symmetric(horizontal: 32), - physics: NeverScrollableScrollPhysics(), - itemCount: files.length, - separatorBuilder: (context, index) => SizedBox(height: 10), - itemBuilder: (context, index) { - final date = DateTime.parse(files[index].date ?? "").toLocal(); - final shortDate = DateFormat('MM/dd/yy').format(date); - final time = DateFormat('kk:mm').format(date); + return SlidableAutoCloseBehavior( + child: ListView.separated( + shrinkWrap: true, + padding: EdgeInsets.symmetric(horizontal: 32), + physics: NeverScrollableScrollPhysics(), + itemCount: files.length, + separatorBuilder: (context, index) => SizedBox(height: 10), + itemBuilder: (context, index) { + final date = DateTime.parse(files[index].date ?? "").toLocal(); + final shortDate = DateFormat('MM/dd/yy').format(date); + final time = DateFormat('kk:mm').format(date); - // late FileTransfer fileTransfer; - // bool isDownloaded = false; + // late FileTransfer fileTransfer; + // bool isDownloaded = false; - // for (var filetransfer in provider.myFiles) { - // if (filetransfer.key == files[index].fileTransferId) { - // fileTransfer = filetransfer; - // break; - // } - // } + // for (var filetransfer in provider.myFiles) { + // if (filetransfer.key == files[index].fileTransferId) { + // fileTransfer = filetransfer; + // break; + // } + // } - return Slidable( - endActionPane: ActionPane( - motion: ScrollMotion(), - extentRatio: 0.11, - children: [ - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: GestureDetector( - onTap: () async { - await openFilePath( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!); - }, - child: SvgPicture.asset( - AppVectors.icSendFile, + return Slidable( + key: UniqueKey(), + endActionPane: ActionPane( + motion: ScrollMotion(), + extentRatio: 0.24, + children: [ + Padding( + padding: const EdgeInsets.only(left: 6.0), + child: GestureDetector( + onTap: () async { + await openFilePath( + BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + files[index].fileName!); + }, + child: SvgPicture.asset( + AppVectors.icSendFile, + ), ), ), - ), - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: GestureDetector( - onTap: () async { - await FileUtils.deleteFile( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - fileTransferId: files[index].fileTransferId, - onComplete: () { - files.removeAt(index); - }, - ); - setState(() {}); - }, - child: SvgPicture.asset( - AppVectors.icDeleteFile, + Padding( + padding: const EdgeInsets.only(left: 6.0), + child: GestureDetector( + onTap: () async { + await FileUtils.deleteFile( + BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + files[index].fileName!, + fileTransferId: files[index].fileTransferId, + onComplete: () { + files.removeAt(index); + }, + ); + setState(() {}); + }, + child: SvgPicture.asset( + AppVectors.icDeleteFile, + ), ), ), - ), - ], - ) + ], + ) - // Consumer( - // builder: (_c, provider, _) { - // var fileTransferProgress = - // provider.receivedFileProgress[fileTransfer.key]; + // Consumer( + // builder: (_c, provider, _) { + // var fileTransferProgress = + // provider.receivedFileProgress[fileTransfer.key]; - // return CommonUtilityFunctions() - // .checkForDownloadAvailability(fileTransfer) - // ? fileTransferProgress != null - // ? CommonUtilityFunctions().getDownloadStatus( - // fileTransferProgress, - // ) - // : isDownloaded - // ? SvgPicture.asset(AppVectors.icCloudDownloaded) - // : InkWell( - // onTap: () async { - // var res = await downloadFiles( - // fileTransfer, - // fileName: files[index].fileName, - // ); + // return CommonUtilityFunctions() + // .checkForDownloadAvailability(fileTransfer) + // ? fileTransferProgress != null + // ? CommonUtilityFunctions().getDownloadStatus( + // fileTransferProgress, + // ) + // : isDownloaded + // ? SvgPicture.asset(AppVectors.icCloudDownloaded) + // : InkWell( + // onTap: () async { + // var res = await downloadFiles( + // fileTransfer, + // fileName: files[index].fileName, + // ); - // setState(() { - // isDownloaded = res; - // }); - // }, - // child: SvgPicture.asset( - // AppVectors.icDownloadFile, - // ), - // ) - // : SizedBox(); - // }, - // ), - // Padding( - // padding: const EdgeInsets.only(left: 6.0), - // child: SvgPicture.asset( - // AppVectors.icDownloadFile, - // ), - // ), + // setState(() { + // isDownloaded = res; + // }); + // }, + // child: SvgPicture.asset( + // AppVectors.icDownloadFile, + // ), + // ) + // : SizedBox(); + // }, + // ), + // Padding( + // padding: const EdgeInsets.only(left: 6.0), + // child: SvgPicture.asset( + // AppVectors.icDownloadFile, + // ), + // ), - , - child: InkWell( - onTap: () async { - await FileUtils.openFile( - path: BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - extension: files[index].fileName?.split(".").last ?? "", - onDelete: () async { - await FileUtils.deleteFile( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!); - if (mounted) { - Navigator.pop(context); - } - setState(() {}); - }, - fileDetail: files[index], - ); - }, - child: Container( - key: UniqueKey(), - padding: EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - ), - child: Row( - children: [ - Container( - height: 49, - width: 38, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5), - ), - child: Center( - child: CommonUtilityFunctions().interactableThumbnail( - files[index].fileName?.split(".").last ?? "", - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - files[index], () async { - await FileUtils.deleteFile( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - fileTransferId: files[index].fileTransferId, - onComplete: () { - files.removeAt(index); - }, - ); + , + child: InkWell( + onTap: () async { + await FileUtils.openFile( + path: BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + files[index].fileName!, + extension: files[index].fileName?.split(".").last ?? "", + onDelete: () async { + await FileUtils.deleteFile( + BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + files[index].fileName!); + if (mounted) { + Navigator.pop(context); + } + setState(() {}); + }, + fileDetail: files[index], + ); + }, + child: Container( + key: UniqueKey(), + padding: EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), + child: Row( + children: [ + Container( + height: 49, + width: 38, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + ), + child: Center( + child: CommonUtilityFunctions().interactableThumbnail( + files[index].fileName?.split(".").last ?? "", + BackendService.getInstance() + .downloadDirectory! + .path + + Platform.pathSeparator + + files[index].fileName!, + files[index], () async { + await FileUtils.deleteFile( + BackendService.getInstance() + .downloadDirectory! + .path + + Platform.pathSeparator + + files[index].fileName!, + fileTransferId: files[index].fileTransferId, + onComplete: () { + files.removeAt(index); + }, + ); - if (mounted) { - Navigator.pop(context); - } - setState(() {}); - }), + if (mounted) { + Navigator.pop(context); + } + setState(() {}); + }), + ), ), - ), - SizedBox(width: 14), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text( - "${files[index].fileName}", + SizedBox(width: 14), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Text( + "${files[index].fileName}", + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w600, + fontSize: 10, + ), + ), + ), + SizedBox(width: 12), + Text( + "$shortDate", style: TextStyle( - color: Colors.black, - fontWeight: FontWeight.w600, fontSize: 10, + color: ColorConstants.oldSliver, ), ), - ), - SizedBox(width: 12), - Text( - "$shortDate", - style: TextStyle( - fontSize: 10, - color: ColorConstants.oldSliver, - ), - ), - Container( - width: 1, - height: 8, - color: Color(0xFFD7D7D7), - margin: EdgeInsets.symmetric( - horizontal: 3, - ), - ), - Text( - "$time", - style: TextStyle( - fontSize: 10, - color: ColorConstants.oldSliver, + Container( + width: 1, + height: 8, + color: Color(0xFFD7D7D7), + margin: EdgeInsets.symmetric( + horizontal: 3, + ), ), - ), - ], - ), - SizedBox(height: 7), - Text( - "${(files[index].contactName)?.split("@")[1] ?? ''}", - style: TextStyle( - color: Colors.black, - fontWeight: FontWeight.w600, - fontSize: 10, - ), - ), - SizedBox(height: 1), - Row( - children: [ - Expanded( - child: Text( - "${files[index].contactName ?? ''}", + Text( + "$time", style: TextStyle( - color: Colors.black, fontSize: 10, + color: ColorConstants.oldSliver, ), ), + ], + ), + SizedBox(height: 7), + Text( + "${(files[index].contactName)?.split("@")[1] ?? ''}", + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w600, + fontSize: 10, ), - Text( - AppUtils.getFileSizeString( - bytes: files[index].size ?? 0, - decimals: 2, - ), - style: TextStyle( - fontSize: 10, - color: ColorConstants.oldSliver, + ), + SizedBox(height: 1), + Row( + children: [ + Expanded( + child: Text( + "${files[index].contactName ?? ''}", + style: TextStyle( + color: Colors.black, + fontSize: 10, + ), + ), ), - ) - ], - ), - ], - ), - ) - ], + Text( + AppUtils.getFileSizeString( + bytes: files[index].size ?? 0, + decimals: 2, + ), + style: TextStyle( + fontSize: 10, + color: ColorConstants.oldSliver, + ), + ) + ], + ), + ], + ), + ) + ], + ), ), ), - ), - ); - }, + ); + }, + ), ); } }