windows_single_instance 0.1.7 windows_single_instance: ^0.1.7 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) {
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"),
),
),
);
}
}