open static method

Future<OpenResult> open(
  1. String? filePath, {
  2. String? type,
  3. String? uti,
  4. String linuxDesktopName = "xdg",
  5. bool linuxByProcess = false,
})

linuxDesktopName like 'xdg'/'gnome'

Implementation

static Future<OpenResult> open(String? filePath,
    {String? type,
    String? uti,
    String linuxDesktopName = "xdg",
    bool linuxByProcess = false}) async {
  assert(filePath != null);
  if (!Platform.isIOS && !Platform.isAndroid) {
    int result;
    int windowsResult = 0;
    if (Platform.isMacOS) {
      result = mac.system(['open', '$filePath']);
    } else if (Platform.isLinux) {
      var filePathLinux = Uri.file(filePath!);
      if (linuxByProcess) {
        result =
            Process.runSync('xdg-open', [filePathLinux.toString()]).exitCode;
      } else {
        result = linux
            .system(['$linuxDesktopName-open', filePathLinux.toString()]);
      }
    } else if (Platform.isWindows) {
      windowsResult = windows.shellExecute('open', filePath!);
      result = windowsResult <= 32 ? 1 : 0;
    } else {
      result = -1;
    }
    return OpenResult(
        type: result == 0 ? ResultType.done : ResultType.error,
        message: result == 0
            ? "done"
            : result == -1
                ? "This operating system is not currently supported"
                : "there are some errors when open $filePath${Platform.isWindows ? "   HINSTANCE=$windowsResult" : ""}");
  }

  Map<String, String?> map = {
    "file_path": filePath!,
    "type": type,
    "uti": uti,
  };
  final result = await _channel.invokeMethod('open_file', map);
  final resultMap = json.decode(result) as Map<String, dynamic>;
  return OpenResult.fromJson(resultMap);
}