Flutter window, multi window and remove title bar

211 Views Asked by At

I am making flutter window app. which needs multiple of windows. I have made new window with desktop_multi_window: ^0.2.0 package. and hide title bar of main window with window_manager: ^0.3.7 package.

but setting from window_manager does not hide new window's title bar. is there way to remove title bar from new window? maybe there is default setting in flutter?

currently I am using flutter 3.13.6.

if there is another way to make new window and hide titlebar. please let me know.

here is minimal example code.

import 'dart:convert';
import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

Future<void> main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();
  if (args.firstOrNull == 'multi_window') {
    final windowId = int.parse(args[1]);
    final argument = args[2].isEmpty
        ? const {}
        : jsonDecode(args[2]) as Map<String, dynamic>;
    runApp(SubWindow(
      windowController: WindowController.fromWindowId(windowId),
      args: argument,
    ));
  } else {
    await windowManager.ensureInitialized();

    WindowOptions windowOptions = const WindowOptions(
      size: Size(400, 400),
      center: true,
      titleBarStyle: TitleBarStyle.hidden,
    );
    windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.show();
      await windowManager.focus();
    });
    runApp(const MyApp());
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example code',
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: ElevatedButton(
          onPressed: () async {
            final window = await DesktopMultiWindow.createWindow(jsonEncode(
                {"arg1": 1}
            ));
            window
              ..setFrame(const Offset(0, 0) & const Size(400, 600))
              ..center()
              ..show();
          },
          child: const Text('Show new window'),
        ),
      ),
    );
  }
}


class SubWindow extends StatelessWidget {
  const SubWindow({
    Key? key,
    required this.windowController,
    required this.args,
  }) : super(key: key);

  final WindowController windowController;
  final Map args;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Text("SubWindow"),
    );
  }
}
0

There are 0 best solutions below