An open-source cross-platform alternative to AirDrop
feat: optimize receive options page
Tien Do Nam76a356a2dd12
diff --git a/app/lib/pages/receive_options_page.dart b/app/lib/pages/receive_options_page.dartindex 28bffbb9..9b1e826b 100644--- a/app/lib/pages/receive_options_page.dart+++ b/app/lib/pages/receive_options_page.dart@@ -34,160 +34,169 @@ class ReceiveOptionsPage extends StatelessWidget {appBar: AppBar(title: Text(t.receiveOptionsPage.title),),- body: ResponsiveListView(+ body: ResponsiveListView.builder(padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),- children: [- Row(- children: [- Text(t.receiveOptionsPage.destination, style: Theme.of(context).textTheme.titleLarge),- if (checkPlatformWithFileSystem())- Padding(- padding: const EdgeInsets.only(left: 10),- child: CustomIconButton(- onPressed: () async {- final directory = await pickDirectoryPath();- if (directory != null) {- ref.notifier(serverProvider).setSessionDestinationDir(directory);- }- },- child: const Icon(Icons.edit),- ),- ),- ],- ),- const SizedBox(height: 5),- Text(checkPlatformWithFileSystem() ? receiveSession.destinationDirectory : t.receiveOptionsPage.appDirectory),- if (checkPlatformWithGallery())- Column(- crossAxisAlignment: CrossAxisAlignment.start,+ itemCount: vm.files.length + 1,+ itemBuilder: (context, index) {+ if (index == 0) {+ // header+ return Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,children: [- const SizedBox(height: 20),- Text(t.receiveOptionsPage.saveToGallery, style: Theme.of(context).textTheme.titleLarge),- const SizedBox(height: 10),Row(children: [- CustomDropdownButton<bool>(- value: receiveSession.saveToGallery,- expanded: false,- items: [false, true].map((b) {- return DropdownMenuItem(- value: b,- alignment: Alignment.center,- child: ConstrainedBox(- constraints: const BoxConstraints(minWidth: 80),- child: Padding(- padding: const EdgeInsets.symmetric(horizontal: 10),- child: Text(b ? t.general.on : t.general.off),- ),+ Text(t.receiveOptionsPage.destination, style: Theme.of(context).textTheme.titleLarge),+ if (checkPlatformWithFileSystem())+ Padding(+ padding: const EdgeInsets.only(left: 10),+ child: CustomIconButton(+ onPressed: () async {+ final directory = await pickDirectoryPath();+ if (directory != null) {+ ref.notifier(serverProvider).setSessionDestinationDir(directory);+ }+ },+ child: const Icon(Icons.edit),+ ),+ ),+ ],+ ),+ const SizedBox(height: 5),+ Text(checkPlatformWithFileSystem() ? receiveSession.destinationDirectory : t.receiveOptionsPage.appDirectory),+ if (checkPlatformWithGallery())+ Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ const SizedBox(height: 20),+ Text(t.receiveOptionsPage.saveToGallery, style: Theme.of(context).textTheme.titleLarge),+ const SizedBox(height: 10),+ Row(+ children: [+ CustomDropdownButton<bool>(+ value: receiveSession.saveToGallery,+ expanded: false,+ items: [false, true].map((b) {+ return DropdownMenuItem(+ value: b,+ alignment: Alignment.center,+ child: ConstrainedBox(+ constraints: const BoxConstraints(minWidth: 80),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 10),+ child: Text(b ? t.general.on : t.general.off),+ ),+ ),+ );+ }).toList(),+ onChanged: (b) => ref.notifier(serverProvider).setSessionSaveToGallery(b),),- );- }).toList(),- onChanged: (b) => ref.notifier(serverProvider).setSessionSaveToGallery(b),- ),- if (receiveSession.containsDirectories && !receiveSession.saveToGallery) ...[- const SizedBox(width: 10),- Expanded(- child: Text(t.receiveOptionsPage.saveToGalleryOff, style: const TextStyle(color: Colors.grey)),+ if (receiveSession.containsDirectories && !receiveSession.saveToGallery) ...[+ const SizedBox(width: 10),+ Expanded(+ child: Text(t.receiveOptionsPage.saveToGalleryOff, style: const TextStyle(color: Colors.grey)),+ ),+ ],+ ],),],+ ),+ const SizedBox(height: 20),+ Row(+ children: [+ Text(t.general.files, style: Theme.of(context).textTheme.titleLarge),+ const SizedBox(width: 10),+ Tooltip(+ message: t.dialogs.quickActions.title,+ child: CustomIconButton(+ onPressed: () async {+ await showDialog(context: context, builder: (_) => const QuickActionsDialog());+ },+ child: const Icon(Icons.tips_and_updates),+ ),+ ),+ const SizedBox(width: 10),+ Tooltip(+ message: t.general.reset,+ child: CustomIconButton(+ onPressed: () => ref.notifier(selectedReceivingFilesProvider).setFiles(vm.files),+ child: const Icon(Icons.undo),+ ),+ ),],),+ const SizedBox(height: 5),],- ),- const SizedBox(height: 20),- Row(- children: [- Text(t.general.files, style: Theme.of(context).textTheme.titleLarge),- const SizedBox(width: 10),- Tooltip(- message: t.dialogs.quickActions.title,- child: CustomIconButton(- onPressed: () async {- await showDialog(context: context, builder: (_) => const QuickActionsDialog());- },- child: const Icon(Icons.tips_and_updates),- ),- ),- const SizedBox(width: 10),- Tooltip(- message: t.general.reset,- child: CustomIconButton(- onPressed: () => ref.notifier(selectedReceivingFilesProvider).setFiles(vm.files),- child: const Icon(Icons.undo),- ),- ),- ],- ),- const SizedBox(height: 5),- ...vm.files.map((file) {- return Padding(- padding: const EdgeInsets.only(bottom: 10),- child: Row(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Icon(file.fileType.icon, size: 46),- const SizedBox(width: 10),- Expanded(- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- selectState[file.id] ?? file.fileName,- style: const TextStyle(fontSize: 16),- maxLines: 1,- overflow: TextOverflow.fade,- softWrap: false,- ),- Text(- '${!selectState.containsKey(file.id) ? t.general.skipped : (selectState[file.id] == file.fileName ? t.general.unchanged : t.general.renamed)} - ${file.size.asReadableFileSize}',- style: TextStyle(- color: !selectState.containsKey(file.id)- ? Colors.grey- : (selectState[file.id] == file.fileName ? Theme.of(context).colorScheme.onSecondaryContainer : Colors.orange),- ),- ),- ],- ),- ),- Row(- mainAxisSize: MainAxisSize.min,+ );+ }++ final file = vm.files[index - 1];+ return Padding(+ padding: const EdgeInsets.only(bottom: 10),+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Icon(file.fileType.icon, size: 46),+ const SizedBox(width: 10),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,children: [- CustomIconButton(- onPressed: selectState[file.id] == null- ? null- : () async {- final result = await showDialog<String>(- context: context,- builder: (_) => FileNameInputDialog(- originalName: file.fileName,- initialName: selectState[file.id]!,- ),- );- if (result != null) {- ref.notifier(selectedReceivingFilesProvider).rename(file.id, result);- }- },- child: const Icon(Icons.edit),+ Text(+ selectState[file.id] ?? file.fileName,+ style: const TextStyle(fontSize: 16),+ maxLines: 1,+ overflow: TextOverflow.fade,+ softWrap: false,),- Checkbox(- value: selectState.containsKey(file.id),- activeColor: Theme.of(context).colorScheme.onSurface,- checkColor: Theme.of(context).colorScheme.surface,- onChanged: (selected) {- if (selected == true) {- ref.notifier(selectedReceivingFilesProvider).select(file);- } else {- ref.notifier(selectedReceivingFilesProvider).unselect(file.id);- }- },+ Text(+ '${!selectState.containsKey(file.id) ? t.general.skipped : (selectState[file.id] == file.fileName ? t.general.unchanged : t.general.renamed)} - ${file.size.asReadableFileSize}',+ style: TextStyle(+ color: !selectState.containsKey(file.id)+ ? Colors.grey+ : (selectState[file.id] == file.fileName ? Theme.of(context).colorScheme.onSecondaryContainer : Colors.orange),+ ),),],),- ],- ),- );- }),- ],+ ),+ Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ CustomIconButton(+ onPressed: selectState[file.id] == null+ ? null+ : () async {+ final result = await showDialog<String>(+ context: context,+ builder: (_) => FileNameInputDialog(+ originalName: file.fileName,+ initialName: selectState[file.id]!,+ ),+ );+ if (result != null) {+ ref.notifier(selectedReceivingFilesProvider).rename(file.id, result);+ }+ },+ child: const Icon(Icons.edit),+ ),+ Checkbox(+ value: selectState.containsKey(file.id),+ activeColor: Theme.of(context).colorScheme.onSurface,+ checkColor: Theme.of(context).colorScheme.surface,+ onChanged: (selected) {+ if (selected == true) {+ ref.notifier(selectedReceivingFilesProvider).select(file);+ } else {+ ref.notifier(selectedReceivingFilesProvider).unselect(file.id);+ }+ },+ ),+ ],+ ),+ ],+ ),+ );+ },),);}diff --git a/app/lib/widget/responsive_list_view.dart b/app/lib/widget/responsive_list_view.dartindex 76ba3a59..420b11e5 100644--- a/app/lib/widget/responsive_list_view.dart+++ b/app/lib/widget/responsive_list_view.dart@@ -11,6 +11,8 @@ class ResponsiveListView extends StatelessWidget {final EdgeInsets desktopPadding;final List<Widget>? children;final Widget? child;+ final int? itemCount;+ final IndexedWidgetBuilder? itemBuilder;const ResponsiveListView.single({this.maxWidth = defaultMaxWidth,@@ -20,7 +22,9 @@ class ResponsiveListView extends StatelessWidget {required Widget this.child,super.key,}) : desktopPadding = tabletPadding ?? const EdgeInsets.symmetric(horizontal: 10, vertical: 30),- children = null;+ children = null,+ itemCount = null,+ itemBuilder = null;const ResponsiveListView({this.maxWidth = defaultMaxWidth,@@ -30,11 +34,44 @@ class ResponsiveListView extends StatelessWidget {required List<Widget> this.children,super.key,}) : desktopPadding = tabletPadding ?? const EdgeInsets.symmetric(horizontal: 10, vertical: 30),+ child = null,+ itemCount = null,+ itemBuilder = null;++ const ResponsiveListView.builder({+ this.maxWidth = defaultMaxWidth,+ this.controller,+ required this.padding,+ EdgeInsets? tabletPadding,+ required int this.itemCount,+ required IndexedWidgetBuilder this.itemBuilder,+ super.key,+ }) : desktopPadding = tabletPadding ?? const EdgeInsets.symmetric(horizontal: 10, vertical: 30),+ children = null,child = null;@overrideWidget build(BuildContext context) {- if (children != null) {+ if (itemBuilder != null) {+ return Center(+ child: ConstrainedBox(+ constraints: BoxConstraints(maxWidth: maxWidth),+ child: ResponsiveBuilder(+ builder: (sizingInformation) {+ final resolvedPadding = sizingInformation.isDesktop ? desktopPadding : padding;+ return ListView.builder(+ controller: controller,+ padding: resolvedPadding.copyWith(+ bottom: resolvedPadding.bottom + getNavBarPadding(context),+ ),+ itemCount: itemCount!,+ itemBuilder: itemBuilder!,+ );+ },+ ),+ ),+ );+ } else if (children != null) {return SingleChildScrollView(controller: controller,child: Center(