mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-17 05:43:41 +00:00
fix: persist download directory changes (#1352)
This commit is contained in:
1 parent
d7f6c3b206
commit
ae70dc240c
1 file changed
+36
-9
@@ -75,6 +75,22 @@ String renderPathPlaceholders(String path) {
|
|||||||
.replaceAll('%date%', date);
|
.replaceAll('%date%', date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateDirectorySelection(
|
||||||
|
TextEditingController controller,
|
||||||
|
String value, {
|
||||||
|
VoidCallback? onChanged,
|
||||||
|
}) {
|
||||||
|
if (controller.text == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controller.value = controller.value.copyWith(
|
||||||
|
text: value,
|
||||||
|
selection: TextSelection.collapsed(offset: value.length),
|
||||||
|
composing: TextRange.empty,
|
||||||
|
);
|
||||||
|
onChanged?.call();
|
||||||
|
}
|
||||||
|
|
||||||
class DirectorySelector extends StatefulWidget {
|
class DirectorySelector extends StatefulWidget {
|
||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
final bool showLabel;
|
final bool showLabel;
|
||||||
@@ -109,7 +125,8 @@ class _DirectorySelectorState extends State<DirectorySelector> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var dir = await FilePicker.platform.getDirectoryPath();
|
var dir = await FilePicker.platform.getDirectoryPath();
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
widget.controller.text = dir;
|
updateDirectorySelection(widget.controller, dir,
|
||||||
|
onChanged: widget.onEditComplete);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -127,12 +144,18 @@ class _DirectorySelectorState extends State<DirectorySelector> {
|
|||||||
customWidths: const [50, 50],
|
customWidths: const [50, 50],
|
||||||
onToggle: (index) async {
|
onToggle: (index) async {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
widget.controller.text =
|
updateDirectorySelection(
|
||||||
(await getExternalStorageDirectory())?.path ??
|
widget.controller,
|
||||||
(await getApplicationDocumentsDirectory()).path;
|
(await getExternalStorageDirectory())?.path ??
|
||||||
|
(await getApplicationDocumentsDirectory()).path,
|
||||||
|
onChanged: widget.onEditComplete,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
widget.controller.text =
|
updateDirectorySelection(
|
||||||
'${(await DownloadsPath.downloadsDirectory())!.path}/Gopeed';
|
widget.controller,
|
||||||
|
'${(await DownloadsPath.downloadsDirectory())!.path}/Gopeed',
|
||||||
|
onChanged: widget.onEditComplete,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cancelToggle: (index) async {
|
cancelToggle: (index) async {
|
||||||
@@ -193,10 +216,14 @@ class _DirectorySelectorState extends State<DirectorySelector> {
|
|||||||
final newText = currentText.substring(0, cursorPosition) +
|
final newText = currentText.substring(0, cursorPosition) +
|
||||||
placeholder +
|
placeholder +
|
||||||
currentText.substring(cursorPosition);
|
currentText.substring(cursorPosition);
|
||||||
widget.controller.text = newText;
|
widget.controller.value = widget.controller.value.copyWith(
|
||||||
widget.controller.selection = TextSelection.fromPosition(
|
text: newText,
|
||||||
TextPosition(offset: cursorPosition + placeholder.length),
|
selection: TextSelection.fromPosition(
|
||||||
|
TextPosition(offset: cursorPosition + placeholder.length),
|
||||||
|
),
|
||||||
|
composing: TextRange.empty,
|
||||||
);
|
);
|
||||||
|
widget.onEditComplete?.call();
|
||||||
},
|
},
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (BuildContext context) {
|
||||||
final placeholders = getPathPlaceholders();
|
final placeholders = getPathPlaceholders();
|
||||||
|
|||||||
Reference in new issue
Block a user