p-hatan/ mirror

pub repository

mirror.p-hatan.ir

bitsdojo_window

0.1.3

A package to help with creating custom windows with Flutter desktop (custom border, titlebar and minimize/maximize/close buttons) and common desktop window operations (show/hide/position on screen) for Windows and macOS

Download archive

Readme

bitsdojo_window

A Flutter package that makes it easy to customize and work with your Flutter desktop app window on Windows, macOS and Linux.

Watch the tutorial to get started. Click the image below to watch the video:

IMAGE ALT TEXT

Features:

- Custom window frame - remove standard Windows/macOS/Linux titlebar and buttons
- Hide window on startup
- Show/hide window
- Move window using Flutter widget
- Minimize/Maximize/Restore/Close window
- Set window size, minimum size and maximum size
- Set window position
- Set window alignment on screen (center/topLeft/topRight/bottomLeft/bottomRight)
- Set window title

Getting Started

Install the package using pubspec.yaml

For Windows apps

Inside your application folder, go to windows\runner\main.cpp and add these two lines at the beginning of the file:

#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);

For macOS apps

Inside your application folder, go to macos\runner\MainFlutterWindow.swift and add this line after the one saying import FlutterMacOS :

import FlutterMacOS
import bitsdojo_window_macos // Add this line

Then change this line from:

class MainFlutterWindow: NSWindow {

to this:

class MainFlutterWindow: BitsdojoWindow {

After changing NSWindow to BitsdojoWindow add these lines below the line you changed:

override func bitsdojo_window_configure() -> UInt {
  return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}

Your code should now look like this:

class MainFlutterWindow: BitsdojoWindow {
    
  override func bitsdojo_window_configure() -> UInt {
    return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
  }
    
  override func awakeFromNib() {
    ... //rest of your code

If you don't want to use a custom frame and prefer the standard window titlebar and buttons, you can remove the BDW_CUSTOM_FRAME flag from the code above.

If you don't want to hide the window on startup, you can remove the BDW_HIDE_ON_STARTUP flag from the code above.

For Linux apps

Inside your application folder, go to linux\my_application.cc and add this line at the beginning of the file:

#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>

Then look for these two lines:

gtk_window_set_default_size(window, 1280, 720);
gtk_widget_show(GTK_WIDGET(window));

and change them to this:

auto bdw = bitsdojo_window_from(window);            // <--- add this line
bdw->setCustomFrame(true);                          // <-- add this line
//gtk_window_set_default_size(window, 1280, 720);   // <-- comment this line
gtk_widget_show(GTK_WIDGET(window));

As you can see, we commented the line calling gtk_window_set_default_size and added these two lines before gtk_widget_show(GTK_WIDGET(window));

auto bdw = bitsdojo_window_from(window);
bdw->setCustomFrame(true);

Flutter app integration

Now go to lib\main.dart and add this code in the main function right after runApp(MyApp()); :

void main() {
  runApp(MyApp());

  // Add this code below

  doWhenWindowReady(() {
    const initialSize = Size(600, 450);
    appWindow.minSize = initialSize;
    appWindow.size = initialSize;
    appWindow.alignment = Alignment.center;
    appWindow.show();
  });
}

This will set an initial size and a minimum size for your application window, center it on the screen and show it on the screen.

You can find examples in the example folder.

Here is an example that displays this window:

import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';

void main() {
  runApp(const MyApp());
  doWhenWindowReady(() {
    final win = appWindow;
    const initialSize = Size(600, 450);
    win.minSize = initialSize;
    win.size = initialSize;
    win.alignment = Alignment.center;
    win.title = "Custom window with Flutter";
    win.show();
  });
}

const borderColor = Color(0xFF805306);

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: WindowBorder(
          color: borderColor,
          width: 1,
          child: Row(
            children: const [LeftSide(), RightSide()],
          ),
        ),
      ),
    );
  }
}

const sidebarColor = Color(0xFFF6A00C);

class LeftSide extends StatelessWidget {
  const LeftSide({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return SizedBox(
        width: 200,
        child: Container(
            color: sidebarColor,
            child: Column(
              children: [
                WindowTitleBarBox(child: MoveWindow()),
                Expanded(child: Container())
              ],
            )));
  }
}

const backgroundStartColor = Color(0xFFFFD500);
const backgroundEndColor = Color(0xFFF6A00C);

class RightSide extends StatelessWidget {
  const RightSide({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [backgroundStartColor, backgroundEndColor],
              stops: [0.0, 1.0]),
        ),
        child: Column(children: [
          WindowTitleBarBox(
            child: Row(
              children: [Expanded(child: MoveWindow()), const WindowButtons()],
            ),
          )
        ]),
      ),
    );
  }
}

final buttonColors = WindowButtonColors(
    iconNormal: const Color(0xFF805306),
    mouseOver: const Color(0xFFF6A00C),
    mouseDown: const Color(0xFF805306),
    iconMouseOver: const Color(0xFF805306),
    iconMouseDown: const Color(0xFFFFD500));

final closeButtonColors = WindowButtonColors(
    mouseOver: const Color(0xFFD32F2F),
    mouseDown: const Color(0xFFB71C1C),
    iconNormal: const Color(0xFF805306),
    iconMouseOver: Colors.white);

class WindowButtons extends StatelessWidget {
  const WindowButtons({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        MinimizeWindowButton(colors: buttonColors),
        MaximizeWindowButton(colors: buttonColors),
        CloseWindowButton(colors: closeButtonColors),
      ],
    );
  }
}

❤️ Sponsors - friends helping this package

I am developing this package in my spare time and any help is appreciated. If you want to help you can become a sponsor.

🙏 Thank you!

Want to help? Become a sponsor

Changelog

0.1.3

- Updated ffi to 2.0.0

0.1.2

- Flutter 3.0 support

0.1.1+1

- Added Linux usage instructions

0.1.1

- Linux support now stable

0.1.0+1

- Fix gtk library name on Linux

0.1.0

- Added null safety support

0.0.9

- Linux support added

0.0.8

- Added macOS readme instructions

0.0.7

- macOS support added

0.0.6

- Works with latest Flutter version (master channel)

0.0.5

- Works with latest Flutter version (dev channel)

0.0.4

- Better integration with other plugins

0.0.3

- Using dpi-aware values for title bar and buttons dimensions
- Dynamically calculating default button padding instead of fixed one

0.0.2

- Added video tutorial link

0.0.1

  • Initial release
    • Custom window frame - remove standard Windows titlebar and buttons
    • Hide window on startup
    • Show/hide window
    • Minimize/Maximize/Restore/Close window
    • Move window using Flutter widget
    • Set window size, minimum size and maximum size
    • Set window position
    • Set window alignment on screen (center/topLeft/topRight/bottomLeft/bottomRight)
    • Set window title

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add bitsdojo_window
pubspec.yaml
name: bitsdojo_window
description: A package to help with creating custom windows with Flutter desktop (custom border, titlebar and minimize/maximize/close buttons) and common desktop window operations (show/hide/position on screen) for Windows and macOS
version: 0.1.3
homepage: https://www.bitsdojo.com
repository: https://github.com/bitsdojo/bitsdojo_window

environment:
  sdk: ">=2.17.0 <3.0.0"
  flutter: ">=1.20.0"

flutter:
  plugin:
    platforms:
      windows:
        default_package: bitsdojo_window_windows
      macos:
        default_package: bitsdojo_window_macos
      linux:
        default_package: bitsdojo_window_linux

dependencies:
  flutter:
    sdk: flutter
  bitsdojo_window_platform_interface: ^0.1.2
    #path: ../bitsdojo_window_platform_interface
  bitsdojo_window_windows: ^0.1.3
    #path: ../bitsdojo_window_windows
  bitsdojo_window_macos: ^0.1.3
    #path: ../bitsdojo_window_macos
  bitsdojo_window_linux: ^0.1.3
    #path: ../bitsdojo_window_linux

Version history

VersionPublishedArchiveSHA-256
0.0.12020-11-27T21:13:04.983117ZDownload355ad0f6a0d7d3bea9b95e49c7af7d6d81640c66d35e0365412700c94632fc6e
0.0.22020-11-28T16:51:14.569854ZDownload77937a14aaf093ac954459277919b93a0235f66c2c0801a7868e8eb5a3322d65
0.0.32020-12-03T16:04:01.399210ZDownloadabf7e75ace6d1645a1b6bddea681c3d14639e7fcc3512e8bc00e8b77a8fb3fb5
0.0.42020-12-30T11:10:18.259251ZDownloada1fc7c5f6fda43ba9397f1700530c20b5c5612570eedff078131afa33e290de6
0.0.52021-02-19T22:37:16.467346ZDownload40a9d94ad0694f68fef9d920ad9b03da284fcb45159ea2c9825fa39795819083
0.0.62021-02-22T17:17:46.134373ZDownloada370652a602556c42b27478eb2eae70ca6b94b64510233c76f6b4bdde09cc0fd
0.0.72021-03-02T21:45:15.370920ZDownload3fe157fc615594a21d42edf14b38bb02a60fd840ed9c66af4954fa7a9b126517
0.0.82021-03-02T21:57:13.613263ZDownload740095f9a254a1cf93755778ebd41ac284a1753bdede6c4ffb2bd2d83102aec8
0.0.92021-03-09T12:07:45.826773ZDownloade7325b4ca99165fdbc6f26ad9ae99f6e2452548e6cd93e733596cef68e239f38
0.1.02021-03-19T18:06:05.109982ZDownloadbb757cf65de38ef3bbc17f9c127ec4517f655c37b6c2731bfb76e363a9cd52d4
0.1.0+12021-04-20T19:37:07.791786ZDownload04ef81a481e960ba150bccdfcf7e5f7e6bbd2a0e526818b486da44306d195e92
0.1.12021-06-09T01:23:08.973269ZDownload1a5ecc9c9f0c70ee401ae6511ecf3df22d9e8c2c5faa34377a808f5548ffe932
0.1.1+12021-06-09T02:06:28.248543ZDownload5826aa4f7c94f01d9b7eef33f4e724c4989df4fe72c9d4f9957d4809e743da33
0.1.22022-05-18T16:57:29.231285ZDownload69afdbea4273d984ef8064be967f8cdc303a79909879867afecbbf56f5ebc35f
0.1.32022-08-31T15:03:11.777147ZDownload2bff0357323121c1aa471a7019a018870c6157f71b769d999df564cc5c773706
0.1.42022-08-31T19:04:26.260064ZDownload103cd62e2004c524a3d867b54abbc43cf84907b5fdbd2f99358a0af45ddc7482
0.1.52022-09-09T15:48:55.447870ZDownload1118bc1cd16e6f358431ca4473af57cc1b287d2ceab46dfab6d59a9463160622
0.1.62023-12-23T14:30:17.736964ZDownload88ef7765dafe52d97d7a3684960fb5d003e3151e662c18645c1641c22b873195

Dependencies

bitsdojo_window_linux "^0.1.3"

bitsdojo_window_macos "^0.1.3"

bitsdojo_window_platform_interface "^0.1.2"

bitsdojo_window_windows "^0.1.3"

flutter { "sdk": "flutter" }