An open-source cross-platform alternative to AirDrop
feat: edit text message in selected files
Tien Do Nam9ed28c7800d0
diff --git a/assets/CHANGELOG.md b/assets/CHANGELOG.mdindex b2304f2f..eb4c61db 100644--- a/assets/CHANGELOG.md+++ b/assets/CHANGELOG.md@@ -3,6 +3,7 @@- feat: add troubleshoot page- feat: add 2 buttons to receive history: open folder + delete history- feat: cleanup scan UI by hiding multiple network interfaces inside the scan button+- feat: edit text message in selected files- feat(ex. iOS): pressing destination directory in progress page will open the directory- feat(android): share apk and install apk- feat(android): Android TV supportdiff --git a/lib/pages/selected_files_page.dart b/lib/pages/selected_files_page.dartindex e8cd1bed..6777496a 100644--- a/lib/pages/selected_files_page.dart+++ b/lib/pages/selected_files_page.dart@@ -9,6 +9,7 @@ import 'package:localsend_app/provider/selection/selected_sending_files_providerimport 'package:localsend_app/util/cache_helper.dart';import 'package:localsend_app/util/file_size_helper.dart';import 'package:localsend_app/util/native/open_file.dart';+import 'package:localsend_app/widget/dialogs/message_input_dialog.dart';import 'package:localsend_app/widget/file_thumbnail.dart';import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:routerino/routerino.dart';@@ -52,6 +53,13 @@ class SelectedFilesPage extends ConsumerWidget {const SizedBox(height: 10),...selectedFiles.mapIndexed((index, file) {+ final String? message;+ if (file.fileType == FileType.text && file.bytes != null) {+ message = utf8.decode(file.bytes!);+ } else {+ message = null;+ }+return Padding(padding: const EdgeInsets.only(bottom: 10),child: InkWell(@@ -72,9 +80,7 @@ class SelectedFilesPage extends ConsumerWidget {crossAxisAlignment: CrossAxisAlignment.start,children: [Text(- file.fileType == FileType.text && file.bytes != null- ? '"${utf8.decode(file.bytes!).replaceAll('\n', ' ')}"'- : file.name,+ message != null ? '"${message.replaceAll('\n', ' ')}"' : file.name,maxLines: 1,overflow: TextOverflow.fade,softWrap: false,@@ -83,8 +89,24 @@ class SelectedFilesPage extends ConsumerWidget {],),),+ if (file.fileType == FileType.text && file.bytes != null)+ TextButton(+ style: TextButton.styleFrom(+ foregroundColor: Theme.of(context).colorScheme.onSurface,+ ),+ onPressed: () async {+ final result = await showDialog<String>(context: context, builder: (_) => MessageInputDialog(initialText: message));+ if (result != null) {+ ref.read(selectedSendingFilesProvider.notifier).removeAt(index);+ ref.read(selectedSendingFilesProvider.notifier).addMessage(result, index: index);+ }+ },+ child: const Icon(Icons.edit),+ ),TextButton(- style: TextButton.styleFrom(foregroundColor: Theme.of(context).colorScheme.onSurface),+ style: TextButton.styleFrom(+ foregroundColor: Theme.of(context).colorScheme.onSurface,+ ),onPressed: () {final currCount = ref.read(selectedSendingFilesProvider).length;ref.read(selectedSendingFilesProvider.notifier).removeAt(index);diff --git a/lib/provider/selection/selected_sending_files_provider.dart b/lib/provider/selection/selected_sending_files_provider.dartindex d71a1275..00752f45 100644--- a/lib/provider/selection/selected_sending_files_provider.dart+++ b/lib/provider/selection/selected_sending_files_provider.dart@@ -26,20 +26,20 @@ class SelectedSendingFilesNotifier extends StateNotifier<List<CrossFile>> {/// Add a simple message/// Internally, the message will be stored into [CrossFile.bytes] as UTF-8- void addMessage(String message) {+ void addMessage(String message, {int? index}) {final List<int> bytes = utf8.encode(message);+ final file = CrossFile(+ name: '${_uuid.v4()}.txt',+ fileType: FileType.text,+ size: bytes.length,+ thumbnail: null,+ asset: null,+ path: null,+ bytes: bytes,+ );state = List.unmodifiable([...state,- CrossFile(- name: '${_uuid.v4()}.txt',- fileType: FileType.text,- size: bytes.length,- thumbnail: null,- asset: null,- path: null,- bytes: bytes,- ),- ]);+ ]..insert(index ?? state.length, file));}Future<void> addFiles<T>({diff --git a/lib/widget/dialogs/message_input_dialog.dart b/lib/widget/dialogs/message_input_dialog.dartindex a63fefc4..b05cb887 100644--- a/lib/widget/dialogs/message_input_dialog.dart+++ b/lib/widget/dialogs/message_input_dialog.dart@@ -3,16 +3,25 @@ import 'package:localsend_app/gen/strings.g.dart';import 'package:routerino/routerino.dart';class MessageInputDialog extends StatefulWidget {- const MessageInputDialog();+ final String? initialText;++ const MessageInputDialog({this.initialText});@overrideState<MessageInputDialog> createState() => _MessageInputDialogState();}class _MessageInputDialogState extends State<MessageInputDialog> {- String _text = '';+ final _textController = TextEditingController();bool _multiline = false;+ @override+ void initState() {+ super.initState();+ _textController.text = widget.initialText ?? '';+ _multiline = _textController.text.contains('\n');+ }+@overrideWidget build(BuildContext context) {return AlertDialog(@@ -22,13 +31,10 @@ class _MessageInputDialogState extends State<MessageInputDialog> {children: [TextFormField(key: ValueKey('m-$_multiline'),- initialValue: _text,+ controller: _textController,keyboardType: _multiline ? TextInputType.multiline : TextInputType.text,maxLines: _multiline ? null : 1,autofocus: true,- onChanged: (s) {- setState(() => _text = s);- },onFieldSubmitted: _multiline ? null : (s) => context.pop(s),),Row(@@ -62,7 +68,7 @@ class _MessageInputDialogState extends State<MessageInputDialog> {backgroundColor: Theme.of(context).buttonTheme.colorScheme!.primary,foregroundColor: Theme.of(context).buttonTheme.colorScheme!.onPrimary,),- onPressed: () => context.pop(_text),+ onPressed: () => context.pop(_textController.text),child: Text(t.general.confirm),),],