isFirstInstance function
Returns whether the current process is the only instance of the app
running. If it returns false, another process is already running; the
command line arguments passed in as args
will be forwarded to the previous
instance to be processed by the onSecondInstance() callback.
void main(List<String> args) async {
if (await isFirstInstance(args)) {
onSecondInstance((args) => print("Args: ${args}"));
print("We are the first instance");
} else {
print("Another instance of this application is running");
}
}
Implementation
Future<bool> isFirstInstance([List<String>? args]) {
return InstanceController.instance.checkFirstInstance(args ?? []);
}