1+ [ ![ Pub Version] ( https://img.shields.io/pub/v/bitsdojo_window )] ( https://pub.dev/packages/bitsdojo_window )
2+ [ ![ Pub Popularity] ( https://img.shields.io/pub/popularity/bitsdojo_window )] ( https://pub.dev/packages/bitsdojo_window )
3+ [ ![ Pub Points] ( https://img.shields.io/pub/points/bitsdojo_window )] ( https://pub.dev/packages/bitsdojo_window )
4+
5+ [ ![ GitHub Stars] ( https://img.shields.io/github/stars/bitsdojo/bitsdojo_window )] ( https://github.com/bitsdojo/bitsdojo_window/stargazers )
6+ [ ![ Build Test] ( https://github.com/bitsdojo/bitsdojo_window/actions/workflows/build_test.yaml/badge.svg )] ( https://github.com/bitsdojo/bitsdojo_window/actions/workflows/build_test.yaml )
7+ [ ![ GitHub License] ( https://img.shields.io/github/license/bitsdojo/bitsdojo_window )] ( https://github.com/bitsdojo/bitsdojo_window/blob/main/LICENSE )
8+
19# bitsdojo_window
210
3- A [ Flutter package] ( https://pub.dev/packages/bitsdojo_window ) that makes it easy to customize and work with your Flutter desktop app window ** on Windows, macOS and Linux** .
11+ A [ Flutter package] ( https://pub.dev/packages/bitsdojo_window ) that makes it easy to customize and work with your Flutter desktop app window on ** Windows** , ** macOS** and ** Linux** .
412
5- Watch the tutorial to get started. Click the image below to watch the video:
13+ Watch the tutorial to get started. Click the image below to watch the video:
614
715[ ![ IMAGE ALT TEXT] ( https://img.youtube.com/vi/bee2AHQpGK4/0.jpg )] ( https://www.youtube.com/watch?v=bee2AHQpGK4 " Click to open ")
816
917<img src =" https://raw.githubusercontent.com/bitsdojo/bitsdojo_window/master/resources/screenshot.png " >
1018
1119** Features** :
1220
13- - Custom window frame - remove standard Windows/macOS/Linux titlebar and buttons
14- - Hide window on startup
15- - Show/hide window
16- - Move window using Flutter widget
17- - Minimize/Maximize/Restore/Close window
18- - Set window size, minimum size and maximum size
19- - Set window position
20- - Set window alignment on screen (center/topLeft/topRight/bottomLeft/bottomRight)
21- - Set window title
21+ - Custom window frame - remove standard Windows/macOS/Linux titlebar and buttons
22+ - Hide window on startup
23+ - Show/hide window
24+ - Move window using Flutter widget
25+ - Minimize/Maximize/Restore/Close window
26+ - Set window size, minimum size and maximum size
27+ - Set window position
28+ - Set window alignment on screen (center/topLeft/topRight/bottomLeft/bottomRight)
29+ - Set window title
2230
2331# Getting Started
2432
25- Install the package using ` pubspec.yaml `
33+ Add the package to your project's ` pubspec.yaml ` file manually or using the command below:
2634
27- # For Windows apps
35+ ``` shell
36+ pub add bitsdojo_window
37+ ```
2838
29- Inside your application folder, go to ` windows\runner\main.cpp ` and add these two lines at the beginning of the file :
39+ The ` pubspec.yaml ` file should look like this :
3040
31- ``` cpp
32- #include < bitsdojo_window_windows/bitsdojo_window_plugin.h>
33- auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
34- ```
41+ ``` diff
42+ // pubspec.yaml
3543
36- # For macOS apps
44+ ...
3745
38- Inside your application folder, go to ` macos\runner\MainFlutterWindow.swift ` and add this line after the one saying ` import FlutterMacOS ` :
46+ dependencies:
47+ flutter:
48+ sdk: flutter
49+ + bitsdojo_window: ^0.1.6
3950
40- ``` swift
41- import FlutterMacOS
42- import bitsdojo_window_macos // Add this line
51+ dev_dependencies:
52+
53+ ...
4354```
4455
45- Then change this line from:
56+ # For Windows apps
4657
47- ``` swift
48- class MainFlutterWindow : NSWindow {
49- ```
58+ Inside your application folder, go to ` windows\runner\main.cpp ` and change the code look like this:
5059
51- to this:
60+ ``` diff
61+ // windows/runner/main.cpp
5262
53- ```swift
54- class MainFlutterWindow : BitsdojoWindow {
55- ```
63+ ...
5664
57- After changing `NSWindow` to `BitsdojoWindow` add these lines below the line you changed:
65+ #include "flutter_window.h"
66+ #include "utils.h"
5867
59- ```swift
60- override func bitsdojo_window_configure () -> UInt {
61- return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
62- }
68+ + #include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
69+ + auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
70+
71+ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
72+
73+ ...
6374```
6475
65- Your code should now look like this:
76+ # For macOS apps
77+
78+ Inside your application folder, go to ` macos\runner\MainFlutterWindow.swift ` and change the code look like this:
79+
80+ ``` diff
81+ // macos/runner/MainFlutterWindow.swift
6682
67- ```swift
68- class MainFlutterWindow : BitsdojoWindow {
69-
70- override func bitsdojo_window_configure () -> UInt {
71- return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
83+ import Cocoa
84+ import FlutterMacOS
85+ + import bitsdojo_window_macos
86+
87+ - class MainFlutterWindow: NSWindow {
88+ + class MainFlutterWindow: BitsdojoWindow {
89+ + override func bitsdojo_window_configure() -> UInt {
90+ + return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
91+ + }
92+ override func awakeFromNib() {
93+
94+ ...
95+
96+ }
7297 }
73-
74- override func awakeFromNib () {
75- ... // rest of your code
7698```
99+
77100#
78101
79102If 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.
@@ -82,57 +105,63 @@ If you don't want to hide the window on startup, you can remove the `BDW_HIDE_ON
82105
83106# For Linux apps
84107
85- Inside your application folder, go to `linux\my_application.cc ` and add this line at the beginning of the file :
108+ Inside your application folder, go to ` linux\my_application.cc ` and change the code look like this :
86109
87- ```cpp
88- #include < bitsdojo_window_linux/ bitsdojo_window_plugin.h >
89- ```
90- Then look for these two lines:
110+ ``` diff
111+ // linux/my_application.cc
91112
92- ```cpp
93- gtk_window_set_default_size (window, 1280 , 720 );
94- gtk_widget_show (GTK_WIDGET (window));
95- ```
96- and change them to this:
113+ ...
114+ #include "flutter/generated_plugin_registrant.h"
115+ + #include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
97116
98- ```cpp
99- auto bdw = bitsdojo_window_from (window); // <--- add this line
100- bdw-> setCustomFrame (true ); // <-- add this line
101- // gtk_window_set_default_size(window, 1280, 720); // <-- comment this line
102- gtk_widget_show (GTK_WIDGET (window));
103- ```
117+ struct _MyApplication {
118+
119+ ...
120+
121+ }
104122
105- 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));`
123+ + auto bdw = bitsdojo_window_from(window);
124+ + bdw->setCustomFrame(true);
125+ - gtk_window_set_default_size(window, 1280, 720);
126+ gtk_widget_show(GTK_WIDGET(window));
127+
128+ g_autoptr(FlDartProject) project = fl_dart_project_new();
129+
130+ ...
131+
132+ }
106133
107- ```cpp
108- auto bdw = bitsdojo_window_from (window);
109- bdw-> setCustomFrame (true );
110134```
111135
112136# Flutter app integration
113137
114- Now go to `lib\main.dart` and add this code in the `main` function right after ` runApp ( MyApp ());` :
138+ Now go to ` lib\main.dart ` and change the code look like this :
115139
116- ```dart
117- void main () {
118- runApp (MyApp ());
140+ ``` diff
141+ // lib/main.dart
119142
120- // Add this code below
143+ import 'package:flutter/material.dart';
144+ + import 'package:bitsdojo_window/bitsdojo_window.dart';
121145
122- doWhenWindowReady (() {
123- const initialSize = Size (600 , 450 );
124- appWindow.minSize = initialSize;
125- appWindow.size = initialSize;
126- appWindow.alignment = Alignment.center ;
127- appWindow.show ();
128- });
129- }
146+ void main() {
147+ runApp(MyApp());
148+
149+ + doWhenWindowReady(() {
150+ + const initialSize = Size(600, 450);
151+ + appWindow.minSize = initialSize;
152+ + appWindow.size = initialSize;
153+ + appWindow.alignment = Alignment.center;
154+ + appWindow.show();
155+ + });
156+ }
130157```
158+
131159This will set an initial size and a minimum size for your application window, center it on the screen and show it on the screen.
132160
133- You can find examples in the ` example` folder.
161+ You can find examples in the [ example] ( ./bitsdojo_window/example ) folder.
134162
135163Here is an example that displays this window:
164+
136165<details >
137166<summary >Click to expand</summary >
138167
@@ -249,9 +278,11 @@ class WindowButtons extends StatelessWidget {
249278 }
250279}
251280```
281+
252282</details >
253283
254284#
285+
255286# ** Want to help? Become a sponsor**
256287
257288I am developing this package in my spare time and any help is appreciated.
@@ -262,4 +293,4 @@ If you want to help you can [become a sponsor](https://github.com/sponsors/bitsd
262293
263294## ☕️ Current sponsors:
264295
265- No sponsors
296+ No sponsors
0 commit comments