windows_single_instance 1.0.1 windows_single_instance: ^1.0.1 copied to clipboard
Forces a single instance of your Windows app, bringing the existing window to the front when a new instance is opened.
import 'package:flutter/material.dart';
import 'package:windows_single_instance/windows_single_instance.dart';
void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
await WindowsSingleInstance.ensureSingleInstance(args, "instance_checker", onSecondWindow: (args) {
// ignore: avoid_print
print(args);
});
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const Center(
child: Text("Demo"),
),
),
);
}
}