fix(ui): reuse shared file path picker for script settings (#1496)

This commit is contained in:
Levi authored and GitHub committed 2026-09-10 23:51:16 +08:00
1 parent bb17c7d48a
commit 8f9bac9e6b
5 files changed
+87 -15

No files matched your search

@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' show Divider, Icons, Scrollbar, ScrollbarOrientation;
import 'package:flutter/widgets.dart';
@@ -1376,12 +1375,7 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
title: index == null ? context.l10n.addScript : context.l10n.editScript,
fieldLabel: context.l10n.scriptPath,
initialValue: index == null ? '' : paths[index],
pickPath: Util.isDesktop()
? () async {
final file = await FilePicker.pickFile();
return file?.path;
}
: null,
pickFile: true,
);
if (value == null || !mounted) return;
_mutateConfig((config) {
@@ -122,7 +122,7 @@ Future<String?> showTextSettingDialog(
required String fieldLabel,
String initialValue = '',
bool requireHttpUrl = false,
Future<String?> Function()? pickPath,
bool pickFile = false,
Future<void> Function(String value)? onTest,
}) async {
final controller = TextEditingController(text: initialValue);
@@ -189,16 +189,12 @@ Future<String?> showTextSettingDialog(
children: [
Text(fieldLabel, style: TextStyle(color: palette.textSecondary, fontSize: 12)),
const SizedBox(height: 6),
if (pickPath == null)
if (!pickFile)
AppTextField(controller: controller)
else
AppPathPickerField(
AppPathPickerField.file(
controller: controller,
desktopWidth: AppDesignTokens.settingsFormControlWidth,
onPick: () async {
final path = await pickPath();
if (path != null && path.isNotEmpty) controller.text = path;
},
),
if (validationMessage != null || testMessage != null) ...[
const SizedBox(height: 8),