0

When the user clicks on the button in my Flutter program, I want to open "E:\Downloads\1.fbx" file on the Windows 3D viewer (Default software - windows).

But the file location is not included in pubspec.yaml file. I cannot find a way to do this. Is there any package or any way to do this?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
HoRiz
  • 706
  • 4
  • 15

2 Answers2

0

You could use the process class to run the executable you want, the seconds param is the list of args to pass to the executable. Give it the file to open. For example something like this should work :

import 'dart:io';


void main() async {

    Process.run("C:/Program Files/Google/Chrome/Application/chrome.exe",["pdf.pdf"]);
}
moulte
  • 521
  • 3
  • 5
  • in this case , file location must include in pubspec.yaml file. – HoRiz Apr 24 '23 at 08:06
  • use something like the package filepicker to ask the location of a file to the user, you will get the selected path and use Process.run to run it – moulte Apr 24 '23 at 08:11
0

@moulte answer is correct for normal software such as Chrome, Zoom, etc.

But, In my case, Windows 3D viewer is not normal software. It's a default one. Can't find the file location of the 3D viewer. (actually, we can find it but, If you use it, you just want to get administrator permissions for your Flutter windows.)

So, I found this method to do my task.

Created Function

void openFile(String filePath) {
    Process.run('cmd', ['/c', 'start', '', filePath]);
  }

Called it when user clicks the button,

onPressed: () {
          String filePath = r'E:\Downloads\go.fbx';
          openFile(filePath);
                                            },

Now, It's on with 3D viewer.

HoRiz
  • 706
  • 4
  • 15