Skip to content

An open-source cross-platform alternative to AirDrop

feat: improve selected files UI

Tien Do Nam93931075097e
diff --git a/assets/i18n/strings.i18n.json b/assets/i18n/strings.i18n.json
index 0f1e1d69..f46d89e6 100644
--- a/assets/i18n/strings.i18n.json
+++ b/assets/i18n/strings.i18n.json
@@ -2,12 +2,14 @@
"appName": "LocalSend",
"general": {
"accept": "Accept",
+ "add": "Add",
"advanced": "Advanced",
"cancel": "Cancel",
"close": "Close",
"continueStr": "Continue",
"decline": "Decline",
"done": "Done",
+ "edit": "Edit",
"error": "Error",
"finished": "Finished",
"hide": "Hide",
@@ -31,8 +33,11 @@
},
"sendTab": {
"title": "Send",
- "selection": "Selection",
- "selectionWithCount": "Selection ({count})",
+ "selection": {
+ "title": "Selection",
+ "files": "Files: {files}",
+ "size": "Size: {size}"
+ },
"picker": {
"file": "File",
"image": "Image",
diff --git a/assets/i18n/strings_de.i18n.json b/assets/i18n/strings_de.i18n.json
index f1f9597d..a9bbaddd 100644
--- a/assets/i18n/strings_de.i18n.json
+++ b/assets/i18n/strings_de.i18n.json
@@ -2,12 +2,14 @@
"appName": "LocalSend",
"general": {
"accept": "Akzeptieren",
+ "add": "Hinzufügen",
"advanced": "Erweitert",
"cancel": "Abbrechen",
"close": "Schließen",
"continueStr": "Weiter",
"decline": "Ablehnen",
"done": "Fertig",
+ "edit": "Bearbeiten",
"error": "Fehler",
"finished": "Abgeschlossen",
"hide": "Verstecken",
@@ -31,8 +33,11 @@
},
"sendTab": {
"title": "Senden",
- "selection": "Auswahl",
- "selectionWithCount": "Auswahl ({count})",
+ "selection": {
+ "title": "Auswahl",
+ "files": "Dateien: {files}",
+ "size": "Größe: {size}"
+ },
"picker": {
"file": "Datei",
"image": "Bild",
diff --git a/lib/model/cross_file.dart b/lib/model/cross_file.dart
index 8cfdd0d1..3c33181a 100644
--- a/lib/model/cross_file.dart
+++ b/lib/model/cross_file.dart
@@ -1,4 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart';
+import 'package:localsend_app/model/file_type.dart';
part 'cross_file.freezed.dart';
@@ -7,6 +8,7 @@ part 'cross_file.freezed.dart';
class CrossFile with _$CrossFile {
const factory CrossFile({
required String name,
+ required FileType fileType,
required int size,
required String? path,
required List<int>? bytes,
diff --git a/lib/pages/selected_files_page.dart b/lib/pages/selected_files_page.dart
new file mode 100644
index 00000000..c4352e93
--- /dev/null
+++ b/lib/pages/selected_files_page.dart
@@ -0,0 +1,68 @@
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:localsend_app/gen/strings.g.dart';
+import 'package:localsend_app/provider/selected_files_provider.dart';
+import 'package:localsend_app/util/file_size_helper.dart';
+
+class SelectedFilesPage extends ConsumerWidget {
+ const SelectedFilesPage();
+
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ final selectedFiles = ref.watch(selectedFilesProvider);
+
+ return Scaffold(
+ appBar: AppBar(
+ title: Text(t.sendTab.selection.title),
+ ),
+ body: ListView(
+ padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 5),
+ child: Text(t.sendTab.selection.files(files: selectedFiles.length)),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(left: 5),
+ child: Text(t.sendTab.selection.size(size: selectedFiles.fold(0, (prev, curr) => prev + curr.size).asReadableFileSize)),
+ ),
+ const SizedBox(height: 10),
+ ...selectedFiles.mapIndexed(
+ (index, file) {
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 10),
+ child: Card(
+ child: Padding(
+ padding: const EdgeInsets.all(10),
+ child: Row(
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(file.name),
+ Text(file.size.asReadableFileSize, style: Theme.of(context).textTheme.caption),
+ ],
+ ),
+ ),
+ IconButton(
+ onPressed: () {
+ final newList = [...selectedFiles];
+ newList.removeAt(index);
+ ref.read(selectedFilesProvider.notifier).state = newList;
+ },
+ icon: const Icon(Icons.delete),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/lib/pages/tabs/send_tab.dart b/lib/pages/tabs/send_tab.dart
index 41e96aa1..eed38378 100644
--- a/lib/pages/tabs/send_tab.dart
+++ b/lib/pages/tabs/send_tab.dart
@@ -1,4 +1,3 @@
-import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -6,15 +5,19 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/cross_file.dart';
+import 'package:localsend_app/pages/selected_files_page.dart';
import 'package:localsend_app/provider/device_info_provider.dart';
import 'package:localsend_app/provider/network/nearby_devices_provider.dart';
import 'package:localsend_app/provider/network/send_provider.dart';
import 'package:localsend_app/provider/network_info_provider.dart';
import 'package:localsend_app/provider/selected_files_provider.dart';
import 'package:localsend_app/provider/settings_provider.dart';
+import 'package:localsend_app/theme.dart';
+import 'package:localsend_app/util/file_path_helper.dart';
import 'package:localsend_app/util/file_size_helper.dart';
import 'package:localsend_app/widget/list_tile/device_list_tile.dart';
import 'package:localsend_app/widget/rotating_widget.dart';
+import 'package:routerino/routerino.dart';
class SendTab extends ConsumerStatefulWidget {
const SendTab({Key? key}) : super(key: key);
@@ -53,42 +56,110 @@ class _SendTabState extends ConsumerState<SendTab> {
return ListView(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),
children: [
- Text(
- selectedFiles.isEmpty ? t.sendTab.selection : t.sendTab.selectionWithCount(count: selectedFiles.length),
- style: Theme.of(context).textTheme.subtitle1,
- ),
- const SizedBox(height: 10),
- ...selectedFiles.mapIndexed((index, file) {
- return Padding(
- padding: const EdgeInsets.only(bottom: 10),
- child: Card(
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Row(
- children: [
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(file.name),
- Text(file.size.asReadableFileSize, style: Theme.of(context).textTheme.caption),
- ],
- ),
+ if (selectedFiles.isEmpty)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 10),
+ child: Text(
+ t.sendTab.selection.title,
+ style: Theme.of(context).textTheme.subtitle1,
+ ),
+ )
+ else
+ ...[
+ Card(
+ margin: EdgeInsets.zero,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 15, top: 15),
+ child: Text(
+ t.sendTab.selection.title,
+ style: Theme.of(context).textTheme.subtitle1,
),
- IconButton(
- onPressed: () {
- final newList = [...selectedFiles];
- newList.removeAt(index);
- ref.read(selectedFilesProvider.notifier).state = newList;
- },
- icon: const Icon(Icons.delete),
+ ),
+ const SizedBox(height: 5),
+ Padding(
+ padding: const EdgeInsets.only(left: 15),
+ child: Text(t.sendTab.selection.files(files: selectedFiles.length)),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(left: 15),
+ child: Text(t.sendTab.selection.size(size: selectedFiles.fold(0, (prev, curr) => prev + curr.size).asReadableFileSize)),
+ ),
+ const SizedBox(height: 10),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 15),
+ child: Row(
+ children: [
+ Expanded(
+ child: Stack(
+ children: [
+ SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ child: Row(
+ children: [
+ ...selectedFiles.map((file) {
+ return Padding(
+ padding: const EdgeInsets.only(right: 10),
+ child: Opacity(
+ opacity: 1,
+ child: Icon(file.fileType.icon, size: 32),
+ ),
+ );
+ }),
+ ],
+ ),
+ ),
+ Positioned.fill(
+ child: IgnorePointer(
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: FractionalOffset.centerLeft,
+ end: FractionalOffset.centerRight,
+ colors: [
+ Colors.transparent,
+ Colors.transparent,
+ Theme.of(context).cardColorWithElevation.withOpacity(0),
+ Theme.of(context).cardColorWithElevation,
+ ],
+ stops: const [0, 0, 0.7, 1],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ElevatedButton.icon(
+ style: IconButton.styleFrom(
+ backgroundColor: Theme.of(context).colorScheme.primary,
+ foregroundColor: Theme.of(context).colorScheme.onPrimary,
+ ),
+ onPressed: () {
+ context.push(() => const SelectedFilesPage());
+ },
+ icon: const Icon(Icons.edit),
+ label: Text(t.general.edit),
+ ),
+ ],
),
- ],
- ),
+ ),
+ const SizedBox(height: 15),
+ ],
),
),
- );
- }),
+ const SizedBox(height: 10),
+ Padding(
+ padding: const EdgeInsets.only(bottom: 10),
+ child: Text(
+ t.general.add,
+ style: Theme.of(context).textTheme.subtitle1,
+ ),
+ ),
+ ],
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -105,6 +176,7 @@ class _SendTabState extends ConsumerState<SendTab> {
...result.files.map((f) {
return CrossFile(
name: f.name,
+ fileType: f.name.guessFileType(),
size: f.size,
path: kIsWeb ? null : f.path,
bytes: kIsWeb ? f.bytes : null,
@@ -128,6 +200,7 @@ class _SendTabState extends ConsumerState<SendTab> {
...await Future.wait(images.map((file) async {
return CrossFile(
name: file.name,
+ fileType: file.name.guessFileType(),
size: await file.length(),
path: kIsWeb ? null : file.path,
bytes: kIsWeb ? await file.readAsBytes() : null,
@@ -153,6 +226,7 @@ class _SendTabState extends ConsumerState<SendTab> {
...selectedFiles,
CrossFile(
name: file.name,
+ fileType: file.name.guessFileType(),
size: await file.length(),
path: kIsWeb ? null : file.path,
bytes: kIsWeb ? await file.readAsBytes() : null,
diff --git a/lib/provider/network/send_provider.dart b/lib/provider/network/send_provider.dart
index 9a554c45..81ad8bb7 100644
--- a/lib/provider/network/send_provider.dart
+++ b/lib/provider/network/send_provider.dart
@@ -16,7 +16,6 @@ import 'package:localsend_app/pages/send_page.dart';
import 'package:localsend_app/provider/device_info_provider.dart';
import 'package:localsend_app/provider/progress_provider.dart';
import 'package:localsend_app/util/api_route_builder.dart';
-import 'package:localsend_app/util/file_path_helper.dart';
import 'package:routerino/routerino.dart';
import 'package:uuid/uuid.dart';
@@ -53,7 +52,7 @@ class SendNotifier extends StateNotifier<SendState?> {
id: id,
fileName: file.name,
size: file.size,
- fileType: file.name.guessFileType(),
+ fileType: file.fileType,
),
status: FileStatus.queue,
token: null,