Closed GroovinChip closed 1 month ago
Hi! You could use the args
of the main function to get the ID of the new Window (0 is the first window) and get also other custom arguments.
This way you should be able to manage to open whatever new Flutter widget tree you want based on the args you passed.
As an example:
import 'package:flutter/material.dart';
import 'package:window_manager_plus/window_manager_plus.dart';
// Must add List<String> args parameter to your main function.
void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
// await the initialization of the plugin.
// Here is an example of how to use ensureInitialized in the main function:
await WindowManagerPlus.ensureInitialized(args.isEmpty ? 0 : int.tryParse(args[0]) ?? 0);
// Now you can use the plugin, such as WindowManagerPlus.current
WindowOptions windowOptions = WindowOptions(
size: Size(800, 600),
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
WindowManagerPlus.current.waitUntilReadyToShow(windowOptions, () async {
await WindowManagerPlus.current.show();
await WindowManagerPlus.current.focus();
});
// check the other args to open whatever you want
if (args.contains('my test arg 1')) {
runApp(MyApp1());
} else {
runApp(MyApp2());
}
// ...
}
When you open a new window, use custom args, such as:
await WindowManagerPlus.createWindow(['my test arg 1', 'my test arg 2']);
Hey there! Great to see more community effort on multi window.
I just tried this out using the example provided in the readme, and I'm seeing that the new window is a copy of the root window. This is not ideal. How can we create windows with different content?
Cheers!