Skip to content
pubscout

windows_single_instance

1.2.0, released 5 months ago by songbook-pro.com

Restrict a Windows app to a single instance and bring existing windows to the front.

WASM-ready
$ flutter pub add windows_single_instance
Source repository

What it does

Forces a single instance of your Windows app, bringing the existing window to the front when a new instance is opened. It allows passing startup arguments and an optional callback when a second instance tries to launch.

AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to prevent users from opening multiple instances of your Windows desktop app
  • You need to bring the existing application window to the foreground when a secondary launch is attempted

Skip it when

  • Your application targets mobile, web, or non-Windows desktop platforms exclusively
  • You want to allow multiple independent instances of your app to run simultaneously

Strengths

  • Brings the correct window to the front even if it is minimized
  • Supports passing custom arguments and exit functions to secondary instances
  • Simple and straightforward setup in the main function

Weaknesses

  • Platform-restricted to Windows
  • Functionality is not supported on web even though it builds

Setup

Kind
Plugin (native code)
Effort
Low
Code generation
No
Direct dependencies
2

Add WidgetsFlutterBinding.ensureInitialized() and make main async, then call WindowsSingleInstance.ensureSingleInstance() with arguments and a unique custom app string.

void main(List<String> args) async {
    WidgetsFlutterBinding.ensureInitialized();
    await WindowsSingleInstance.ensureSingleInstance(
        args,
        "custom_identifier",
        onSecondWindow: (args) {
            print(args);
        });
    runApp(const MyApp());
}

Alternatives

Packages that do the same job and could replace windows_single_instance.

Works with

Packages commonly used together with windows_single_instance: ones it builds on, ones built on it, and its own family.