pub repository
mirror.p-hatan.irbitsdojo_window
0.0.9A 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
Readme
bitsdojo_window
A Flutter package that makes it easy to customize and work with your Flutter desktop app window on both Windows and macOS .
Watch the tutorial to get started. Click the image below to watch the video:
Features:
- Custom window frame - remove standard Windows/macOS 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
Currently working with Flutter desktop apps for Windows and macOS. Linux support is also planned in the future.
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.
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(() {
final 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(MyApp());
doWhenWindowReady(() {
final win = appWindow;
final 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 {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: Row(children: [LeftSide(), RightSide()]))));
}
}
const sidebarColor = Color(0xFFF6A00C);
class LeftSide extends StatelessWidget {
@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 {
@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
decoration: 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()),
WindowButtons()
])),
])));
}
}
const buttonColors = WindowButtonColors(
iconNormal: Color(0xFF805306),
mouseOver: Color(0xFFF6A00C),
mouseDown: Color(0xFF805306),
iconMouseOver: Color(0xFF805306),
iconMouseDown: Color(0xFFFFD500));
const closeButtonColors = WindowButtonColors(
mouseOver: Color(0xFFD32F2F),
mouseDown: Color(0xFFB71C1C),
iconNormal: Color(0xFF805306),
iconMouseOver: Colors.white);
class WindowButtons extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
TODO: More docs coming soon
Changelog
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_windowpubspec.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.0.9
homepage: https://www.bitsdojo.com
repository: https://github.com/bitsdojo/bitsdojo_window
environment:
sdk: ">=2.7.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.0.2
#path: ../bitsdojo_window_platform_interface
bitsdojo_window_windows: ^0.0.3
#path: ../bitsdojo_window_windows
bitsdojo_window_macos: ^0.0.3
#path: ../bitsdojo_window_macos
bitsdojo_window_linux: ^0.0.1
#path: ../bitsdojo_window_linux
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2020-11-27T21:13:04.983117Z | Download | 355ad0f6a0d7d3bea9b95e49c7af7d6d81640c66d35e0365412700c94632fc6e |
| 0.0.2 | 2020-11-28T16:51:14.569854Z | Download | 77937a14aaf093ac954459277919b93a0235f66c2c0801a7868e8eb5a3322d65 |
| 0.0.3 | 2020-12-03T16:04:01.399210Z | Download | abf7e75ace6d1645a1b6bddea681c3d14639e7fcc3512e8bc00e8b77a8fb3fb5 |
| 0.0.4 | 2020-12-30T11:10:18.259251Z | Download | a1fc7c5f6fda43ba9397f1700530c20b5c5612570eedff078131afa33e290de6 |
| 0.0.5 | 2021-02-19T22:37:16.467346Z | Download | 40a9d94ad0694f68fef9d920ad9b03da284fcb45159ea2c9825fa39795819083 |
| 0.0.6 | 2021-02-22T17:17:46.134373Z | Download | a370652a602556c42b27478eb2eae70ca6b94b64510233c76f6b4bdde09cc0fd |
| 0.0.7 | 2021-03-02T21:45:15.370920Z | Download | 3fe157fc615594a21d42edf14b38bb02a60fd840ed9c66af4954fa7a9b126517 |
| 0.0.8 | 2021-03-02T21:57:13.613263Z | Download | 740095f9a254a1cf93755778ebd41ac284a1753bdede6c4ffb2bd2d83102aec8 |
| 0.0.9 | 2021-03-09T12:07:45.826773Z | Download | e7325b4ca99165fdbc6f26ad9ae99f6e2452548e6cd93e733596cef68e239f38 |
| 0.1.0 | 2021-03-19T18:06:05.109982Z | Download | bb757cf65de38ef3bbc17f9c127ec4517f655c37b6c2731bfb76e363a9cd52d4 |
| 0.1.0+1 | 2021-04-20T19:37:07.791786Z | Download | 04ef81a481e960ba150bccdfcf7e5f7e6bbd2a0e526818b486da44306d195e92 |
| 0.1.1 | 2021-06-09T01:23:08.973269Z | Download | 1a5ecc9c9f0c70ee401ae6511ecf3df22d9e8c2c5faa34377a808f5548ffe932 |
| 0.1.1+1 | 2021-06-09T02:06:28.248543Z | Download | 5826aa4f7c94f01d9b7eef33f4e724c4989df4fe72c9d4f9957d4809e743da33 |
| 0.1.2 | 2022-05-18T16:57:29.231285Z | Download | 69afdbea4273d984ef8064be967f8cdc303a79909879867afecbbf56f5ebc35f |
| 0.1.3 | 2022-08-31T15:03:11.777147Z | Download | 2bff0357323121c1aa471a7019a018870c6157f71b769d999df564cc5c773706 |
| 0.1.4 | 2022-08-31T19:04:26.260064Z | Download | 103cd62e2004c524a3d867b54abbc43cf84907b5fdbd2f99358a0af45ddc7482 |
| 0.1.5 | 2022-09-09T15:48:55.447870Z | Download | 1118bc1cd16e6f358431ca4473af57cc1b287d2ceab46dfab6d59a9463160622 |
| 0.1.6 | 2023-12-23T14:30:17.736964Z | Download | 88ef7765dafe52d97d7a3684960fb5d003e3151e662c18645c1641c22b873195 |
Dependencies
bitsdojo_window_linux "^0.0.1"
bitsdojo_window_macos "^0.0.3"
bitsdojo_window_platform_interface "^0.0.2"
bitsdojo_window_windows "^0.0.3"
flutter {
"sdk": "flutter"
}