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
+
1
9
# bitsdojo_window
2
10
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** .
4
12
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:
6
14
7
15
[ ![ IMAGE ALT TEXT] ( https://img.youtube.com/vi/bee2AHQpGK4/0.jpg )] ( https://www.youtube.com/watch?v=bee2AHQpGK4 " Click to open ")
8
16
9
17
<img src =" https://raw.githubusercontent.com/bitsdojo/bitsdojo_window/master/resources/screenshot.png " >
10
18
11
19
** Features** :
12
20
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
22
30
23
31
# Getting Started
24
32
25
- Install the package using ` pubspec.yaml `
33
+ Add the package to your project's ` pubspec.yaml ` file manually or using the command below:
26
34
27
- # For Windows apps
35
+ ``` shell
36
+ pub add bitsdojo_window
37
+ ```
28
38
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 :
30
40
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
35
43
36
- # For macOS apps
44
+ ...
37
45
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
39
50
40
- ``` swift
41
- import FlutterMacOS
42
- import bitsdojo_window_macos // Add this line
51
+ dev_dependencies:
52
+
53
+ ...
43
54
```
44
55
45
- Then change this line from:
56
+ # For Windows apps
46
57
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:
50
59
51
- to this:
60
+ ``` diff
61
+ // windows/runner/main.cpp
52
62
53
- ```swift
54
- class MainFlutterWindow : BitsdojoWindow {
55
- ```
63
+ ...
56
64
57
- After changing `NSWindow` to `BitsdojoWindow` add these lines below the line you changed:
65
+ #include "flutter_window.h"
66
+ #include "utils.h"
58
67
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
+ ...
63
74
```
64
75
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
66
82
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
+ }
72
97
}
73
-
74
- override func awakeFromNib () {
75
- ... // rest of your code
76
98
```
99
+
77
100
#
78
101
79
102
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.
@@ -82,57 +105,63 @@ If you don't want to hide the window on startup, you can remove the `BDW_HIDE_ON
82
105
83
106
# For Linux apps
84
107
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 :
86
109
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
91
112
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>
97
116
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
+ }
104
122
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
+ }
106
133
107
- ```cpp
108
- auto bdw = bitsdojo_window_from (window);
109
- bdw-> setCustomFrame (true );
110
134
```
111
135
112
136
# Flutter app integration
113
137
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 :
115
139
116
- ```dart
117
- void main () {
118
- runApp (MyApp ());
140
+ ``` diff
141
+ // lib/main.dart
119
142
120
- // Add this code below
143
+ import 'package:flutter/material.dart';
144
+ + import 'package:bitsdojo_window/bitsdojo_window.dart';
121
145
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
+ }
130
157
```
158
+
131
159
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.
132
160
133
- You can find examples in the ` example` folder.
161
+ You can find examples in the [ example] ( ./bitsdojo_window/example ) folder.
134
162
135
163
Here is an example that displays this window:
164
+
136
165
<details >
137
166
<summary >Click to expand</summary >
138
167
@@ -249,9 +278,11 @@ class WindowButtons extends StatelessWidget {
249
278
}
250
279
}
251
280
```
281
+
252
282
</details >
253
283
254
284
#
285
+
255
286
# ** Want to help? Become a sponsor**
256
287
257
288
I 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
262
293
263
294
## ☕️ Current sponsors:
264
295
265
- No sponsors
296
+ No sponsors
0 commit comments