How to launch another app from the flutter desktop application?

Viewed 18

I have a flutter application that communicates to a server in the same machine. So now I need to start the server with the flutter app automatically. So is there any way to start the server when I start the flutter app and kill the server when I close the flutter app?

1 Answers

If is in windows you can use the package Win32 : https://pub.dev/packages/win32

try {
   final verb = 'open'.toNativeUtf16();
   final process = 'app.exe'.toNativeUtf16();
   final params = 'p1'.toNativeUtf16();
   final nullParams = ''.toNativeUtf16();
   ShellExecute(0, verb, process, params, nullParams, SW_SHOW);
   return true;
}catch(_){
   return false;
}

For Linux u can use process run: https://pub.dev/packages/process_run

var shell = Shell();

await shell.run('''
 app.sh
''');
Related