Przeglądaj źródła

Used new TextInputDialog for renaming a file

ashilkn 2 lat temu
rodzic
commit
8602a68a1d
1 zmienionych plików z 30 dodań i 29 usunięć
  1. 30 29
      lib/utils/magic_util.dart

+ 30 - 29
lib/utils/magic_util.dart

@@ -9,7 +9,6 @@ import 'package:photos/models/magic_metadata.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/file_magic_service.dart';
 import 'package:photos/ui/common/progress_dialog.dart';
-import 'package:photos/ui/common/rename_dialog.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/toast_util.dart';
 
@@ -94,37 +93,39 @@ Future<bool> editTime(
   }
 }
 
-Future<bool> editFilename(
+Future<void> editFilename(
   BuildContext context,
   File file,
 ) async {
-  try {
-    final fileName = file.displayName;
-    final nameWithoutExt = basenameWithoutExtension(fileName);
-    final extName = extension(fileName);
-    var result = await showDialog<String>(
-      context: context,
-      builder: (BuildContext context) {
-        return RenameDialog(nameWithoutExt, 'file', maxLength: 50);
-      },
-      barrierColor: Colors.black.withOpacity(0.85),
-    );
-
-    if (result == null || result.trim() == nameWithoutExt.trim()) {
-      return true;
-    }
-    result = result + extName;
-    await _updatePublicMetadata(
-      context,
-      List.of([file]),
-      pubMagicKeyEditedName,
-      result,
-    );
-    return true;
-  } catch (e) {
-    showShortToast(context, 'Something went wrong');
-    return false;
-  }
+  final fileName = file.displayName;
+  final nameWithoutExt = basenameWithoutExtension(fileName);
+  final extName = extension(fileName);
+  await showTextInputDialog(
+    context,
+    title: "Rename file",
+    confirmationButtonLabel: "Rename",
+    initialValue: nameWithoutExt,
+    message: extName,
+    alignMessage: Alignment.centerRight,
+    hintText: "Enter file name",
+    maxLength: 50,
+    onConfirm: (String text) async {
+      try {
+        if (text.isEmpty || text.trim() == nameWithoutExt.trim()) {
+          return;
+        }
+        final newName = text + extName;
+        await _updatePublicMetadata(
+          context,
+          List.of([file]),
+          pubMagicKeyEditedName,
+          newName,
+        );
+      } catch (e) {
+        showShortToast(context, 'Something went wrong');
+      }
+    },
+  );
 }
 
 Future<bool> editFileCaption(