multiview_desktop 1.0.0 copy "multiview_desktop: ^1.0.0" to clipboard
multiview_desktop: ^1.0.0 copied to clipboard

Flutter desktop library for managing multiple OS windows from a single Flutter engine and a single Dart isolate. Supports macOS, Windows, and Linux (Wayland).

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:multiview_desktop/multiview_desktop.dart';
import 'pages/home.dart';
import 'utils/theme_config.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runMultiApp(
    home: const MainWindowRoot(),
    config: MultiAppConfig(
      generalParams: MultiPlatformParams(enableDynamicAnchor: true, closeMode: CloseMode.cascade),
      macosParams: MacosPlatformParams(
        saveLastWindowToReopen: true,
        closeAppAfterLastWindowClosed: false,
        onTaskbarTap: null,
      ),
      globalWindowOptions: WindowOptions(
        minimumSize: Size(1000, 700),
        maximumSize: Size(1200, 800),
        size: Size(1000, 700),
        alignment: Alignment.center,
        hideAppFromTaskbar: false,
        titleBarStyle: TitleBarStyle.normal,
        windowButtonVisibility: true,
        title: 'Window 1',
      ),
    ),
  );
}

// ---------------------------------------------------------------------------
// Root widget for the main window
// ---------------------------------------------------------------------------

/// Root widget for the initial (main) OS window.
///
/// Every secondary window opened via [openWindow] uses [_SecondaryWindowRoot]
/// which is defined inside pages/home.dart and shares the same [themeConfig]
/// singleton.
class MainWindowRoot extends StatefulWidget {
  const MainWindowRoot({super.key});

  @override
  State<MainWindowRoot> createState() => _MainWindowRootState();
}

class _MainWindowRootState extends State<MainWindowRoot> {
  @override
  void initState() {
    super.initState();
    themeConfig.addListener(_onThemeChanged);

    MultiViewDesktop.communicator.onBroadcast.listen((msg) {
      if (msg is! Map) return;
      if (msg['type'] != 'themeMode') return;
      if (!mounted) return;
      final mode = ThemeMode.values.firstWhere((m) => m.name == msg['value'], orElse: () => ThemeMode.light);
      MultiViewDesktop.of(context).setBrightness(mode == ThemeMode.dark ? Brightness.dark : Brightness.light);
    });

    WidgetsBinding.instance.addPostFrameCallback((_) async {
      await MultiViewDesktop.of(context).setBrightness(
        themeConfig.themeMode == ThemeMode.dark ? Brightness.dark : Brightness.light,
      );

      sharedConfig.isHideAppFromTaskbar = await MultiViewDesktop.isHideAppFromTaskbar();
      sharedConfig.closeMode = MultiViewDesktop.getCloseMode();
      sharedConfig.anchorId = MultiViewDesktop.getAnchorId();
    });
  }

  @override
  void dispose() {
    themeConfig.removeListener(_onThemeChanged);
    super.dispose();
  }

  void _onThemeChanged() {
    if (mounted) setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      themeMode: themeConfig.themeMode,
      theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true),
      darkTheme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple, brightness: Brightness.dark),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}
1
likes
160
points
0
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter desktop library for managing multiple OS windows from a single Flutter engine and a single Dart isolate. Supports macOS, Windows, and Linux (Wayland).

Repository (GitHub)
View/report issues

Topics

#window #window-customize #window-manager #multi-window #desktop

License

MIT (license)

Dependencies

flutter

More

Packages that depend on multiview_desktop

Packages that implement multiview_desktop