flutter_file_picker
flutter_file_picker copied to clipboard
add ofnNoChangeDir to make desktop consistent for windows
Before this changes, If we used pickFiles
on Windows, the current directory would be changed. And the behavior is inconsistent with Linux and Macos, that those never modify current directory. Issue: https://github.com/miguelpruivo/flutter_file_picker/issues/804
For example (from example):
void _pickFiles() async {
_resetState();
try {
_directoryPath = null;
print(Directory.current.path);
_paths = (await FilePicker.platform.pickFiles(
type: _pickingType,
allowMultiple: _multiPick,
onFileLoading: (FilePickerStatus status) => print(status),
allowedExtensions: (_extension?.isNotEmpty ?? false)
? _extension?.replaceAll(' ', '').split(',')
: null,
))
?.files;
print(Directory.current.path);
} on PlatformException catch (e) {
_logException('Unsupported operation' + e.toString());
} catch (e) {
_logException(e.toString());
}
if (!mounted) return;
setState(() {
_isLoading = false;
_fileName =
_paths != null ? _paths!.map((e) => e.name).toString() : '...';
_userAborted = _paths == null;
});
}
Will output: (If I select file from C)
C:\flutter_picker_file\example
C:\
So I add the OFN_NOCHANGEDIR
flag to prevent current directory from changing by default on Windows. Reference here.
Then using the sample code will output:
C:\flutter_picker_file\example
C:\flutter_picker_file\example
This make the same logic as MacOS and Linux.
@philenius can you take a look?
@Tokenyet would you mind to also update the pubspec and changelog?
Thank you!
@Tokenyet would you mind to also update the pubspec and changelog?
Thank you!
Done! I think It's more like a bug fix rather than a new feature. If there is any problem, please Iet me know.
I have the same problem
hey @Tokenyet, I'm sorry that I wasn't active last year when you initially created this PR. Thank you for your input. I included your changes in #1256 and gave you credit in our CHANGELOG.md
. Thanks again for pointing me in the right direction and sorry for the delay.