Merge pull request 'Fix: #344 - Folder Selection on Settings can be Opened Multiple times' (#402) from small_edits into trunk
continuous-integration/drone/push Build is pending
Details
continuous-integration/drone/push Build is pending
Details
Reviewed-on: #402
This commit is contained in:
commit
d7d3b2ef97
|
@ -42,3 +42,17 @@ Future<String?> showCreateFilePicker(BuildContext ctx) async {
|
||||||
appstate.disableFilePicker = false;
|
appstate.disableFilePicker = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String?> showSelectDirectoryPicker(BuildContext ctx) async {
|
||||||
|
// only allow one file picker at a time
|
||||||
|
// note: ideally we would destroy file picker when leaving a conversation
|
||||||
|
// but we don't currently have that option.
|
||||||
|
// we need to store AppState in a variable because ctx might be destroyed
|
||||||
|
// while awaiting for pickFiles.
|
||||||
|
var appstate = Provider.of<AppState>(ctx, listen: false);
|
||||||
|
appstate.disableFilePicker = true;
|
||||||
|
// currently lockParentWindow only works on Windows...
|
||||||
|
String? result = await FilePicker.platform.getDirectoryPath(lockParentWindow: true);
|
||||||
|
appstate.disableFilePicker = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
import 'package:cwtch/config.dart';
|
||||||
|
import 'package:cwtch/controllers/filesharing.dart';
|
||||||
import 'package:cwtch/cwtch_icons_icons.dart';
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
||||||
|
import 'package:cwtch/models/appstate.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
@ -43,27 +46,25 @@ class _CwtchFolderPickerState extends State<CwtchFolderPicker> {
|
||||||
testKey: widget.testKey,
|
testKey: widget.testKey,
|
||||||
controller: ctrlrVal,
|
controller: ctrlrVal,
|
||||||
readonly: Platform.isAndroid,
|
readonly: Platform.isAndroid,
|
||||||
onPressed: () async {
|
onPressed: Provider.of<AppState>(context).disableFilePicker
|
||||||
if (Platform.isAndroid) {
|
? null
|
||||||
return;
|
: () async {
|
||||||
}
|
if (Platform.isAndroid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
var selectedDirectory = await showSelectDirectoryPicker(context);
|
||||||
var selectedDirectory = await getDirectoryPath();
|
if (selectedDirectory != null) {
|
||||||
if (selectedDirectory != null) {
|
//File directory = File(selectedDirectory);
|
||||||
//File directory = File(selectedDirectory);
|
selectedDirectory += "/";
|
||||||
selectedDirectory += "/";
|
ctrlrVal.text = selectedDirectory;
|
||||||
ctrlrVal.text = selectedDirectory;
|
if (widget.onSave != null) {
|
||||||
if (widget.onSave != null) {
|
widget.onSave!(selectedDirectory);
|
||||||
widget.onSave!(selectedDirectory);
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
// User canceled the picker
|
||||||
// User canceled the picker
|
}
|
||||||
}
|
},
|
||||||
} catch (e) {
|
|
||||||
print(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onChanged: widget.onSave,
|
onChanged: widget.onSave,
|
||||||
icon: Icon(Icons.folder),
|
icon: Icon(Icons.folder),
|
||||||
tooltip: widget.tooltip,
|
tooltip: widget.tooltip,
|
||||||
|
|
Loading…
Reference in New Issue