openFile function

Future<XFile?> openFile({
  1. List<XTypeGroup> acceptedTypeGroups = const <XTypeGroup>[],
  2. String? initialDirectory,
  3. String? confirmButtonText,
})

Opens a file selection dialog and returns the path chosen by the user.

acceptedTypeGroups is a list of file type groups that can be selected in the dialog. How this is displayed depends on the platform, for example:

  • On Windows and Linux, each group will be an entry in a list of filter options.
  • On macOS, the union of all types allowed by all of the groups will be allowed. Throws an ArgumentError if any type groups do not include filters supported by the current platform.

initialDirectory is the full path to the directory that will be displayed when the dialog is opened. When not provided, the platform will pick an initial location. This is ignored on the Web platform.

confirmButtonText is the text in the confirmation button of the dialog. When not provided, the default OS label is used (for example, "Open"). This is ignored on the Web platform.

Returns null if the user cancels the operation.

Implementation

Future<XFile?> openFile({
  List<XTypeGroup> acceptedTypeGroups = const <XTypeGroup>[],
  String? initialDirectory,
  String? confirmButtonText,
}) {
  return FileSelectorPlatform.instance.openFile(
      acceptedTypeGroups: acceptedTypeGroups,
      initialDirectory: initialDirectory,
      confirmButtonText: confirmButtonText);
}