multi_window_native 1.0.4 copy "multi_window_native: ^1.0.4" to clipboard
multi_window_native: ^1.0.4 copied to clipboard

A Flutter plugin for creating and managing multiple native desktop windows with cross-window communication.

multi_window_native

A Flutter plugin that enables native multi-window support on macOS and Windows. It allows you to create and manage multiple Flutter windows, communicate between them, and synchronize UI state across windows. This package requires the use of window manager to handle multiple windows individually.

✨ Features

  1. Create new secondary Flutter windows.

  2. Broadcast messages between windows using method channels.

  3. Pass theme & route arguments when creating windows.

  4. Listen for updates via Dart-side listeners (registerListener / unregisterListener).

  5. Automatically registers plugins for each new window engine.

  6. Native macOS and Windows implementation with seamless Dart integration.

πŸš€ Installation

Add to your pubspec.yaml:

dependencies:
multi_window_native: ^1.0.0

Then run:

flutter pub get

πŸ–ΌοΈ Screenshots

In Windows - Main window Main window with multi-window support

Secondary window Example of a secondary window opened by the plugin

In Macos -

Main window Main window with multi-window support

Secondary window Example of a secondary window opened by the plugin

Theme changes- Both windows

πŸ› οΈ Setup (macOS)

No extra setup required. The plugin will automatically:

Register plugins for newly created window engines.

Keep track of all FlutterBinaryMessenger instances for broadcasting.

πŸ“– Usage

Import the package:

import 'package:multi_window_native/multi_window_native.dart';

Create a new instance and window:

final _multiWindowNative = MultiWindowNative();

void _openWindow() async {
  await _multiWindowNative.createWindow([
    'secondScreen', // Route name
    '{}', // Arguments as JSON string
    'light' // Theme mode
  ]);
}

To access window IDs, initialize the window manager early in your app. It offers methods such as windowFocus and windowClose to manage window lifecycle events like focusing and closing windows.

await windowManager.ensureInitialized();

Notify native when UI is ready to be rendered: The secondary window screen should call this in init state to notify native. NOTE - Its an mandatory step to avoid black screen issues.

@override
void initState() {
  super.initState();
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    await WidgetsBinding.instance.endOfFrame;
    await _multiWindowNative.notifyUiRendered();
  });
}

Communication between windows:

Send updates from Dart to native (and broadcast to all windows):

await _multiWindowNative.notifyAllWindows(
  "updateText",
  {"message": "Hello from Main Window"},
);

Listen for updates in each window:

late String _listenerId;
String _text = "";

@override
void initState() {
  super.initState();
  _listenerId = MultiWindowNative.registerListener("updateText", (call) async {
    setState(() {
      _text = (call.arguments as Map)['message'] ?? "";
    });
  });
}

@override
void dispose() {
  MultiWindowNative.unregisterListener(
    methodName: "updateText", id: _listenerId);
  super.dispose();
}

πŸ“Š API Reference

createWindow(List

closeWindow(): Closes the current window.

notifyUiRendered(): Informs native that the window is ready to display.

notifyAllWindows(String method, dynamic arguments): Broadcasts a method call to all windows.

registerListener(String method, MethodCallHandler handler): Registers a listener for method calls from native. Returns an id.

unregisterListener({required String methodName, required String id}): Unregisters a specific listener by method and id.

πŸ“Œ Notes

Supports macOS and Windows both.

Linux support may be added in future releases.

Each secondary window runs its own Flutter engine.

πŸ“„ License

MIT License. See LICENSE for details.

9
likes
140
points
78
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for creating and managing multiple native desktop windows with cross-window communication.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface, window_manager

More

Packages that depend on multi_window_native

Packages that implement multi_window_native