Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork242
A Flutter package that makes it easy to customize and work with your Flutter desktop app window.
License
bitsdojo/bitsdojo_window
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
AFlutter package that makes it easy to customize and work with your Flutter desktop app window onWindows,macOS andLinux.
Watch the tutorial to get started. Click the image below to watch the video:
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
Add the package to your project'spubspec.yaml file manually or using the command below:
pub add bitsdojo_window
Thepubspec.yaml file should look like this:
// pubspec.yaml ... dependencies: flutter: sdk: flutter+ bitsdojo_window: ^0.1.6 dev_dependencies: ...Inside your application folder, go towindows\runner\main.cpp and change the code look like this:
// windows/runner/main.cpp ... #include "flutter_window.h" #include "utils.h"+ #include <bitsdojo_window_windows/bitsdojo_window_plugin.h>+ auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP); int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, ...
Inside your application folder, go tomacos\runner\MainFlutterWindow.swift and change the code look like this:
// macos/runner/MainFlutterWindow.swift import Cocoa import FlutterMacOS+ import bitsdojo_window_macos- class MainFlutterWindow: NSWindow {+ class MainFlutterWindow: BitsdojoWindow {+ override func bitsdojo_window_configure() -> UInt {+ return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP+ } override func awakeFromNib() { ... } }
If you don't want to use a custom frame and prefer the standard window titlebar and buttons, you can remove theBDW_CUSTOM_FRAME flag from the code above.
If you don't want to hide the window on startup, you can remove theBDW_HIDE_ON_STARTUP flag from the code above.
Inside your application folder, go tolinux\my_application.cc and change the code look like this:
// linux/my_application.cc ... #include "flutter/generated_plugin_registrant.h"+ #include <bitsdojo_window_linux/bitsdojo_window_plugin.h> struct _MyApplication { ... }+ auto bdw = bitsdojo_window_from(window);+ bdw->setCustomFrame(true);- gtk_window_set_default_size(window, 1280, 720); gtk_widget_show(GTK_WIDGET(window)); g_autoptr(FlDartProject) project = fl_dart_project_new(); ... }
Now go tolib\main.dart and change the code look like this:
// lib/main.dart import 'package:flutter/material.dart';+ import 'package:bitsdojo_window/bitsdojo_window.dart'; void main() { runApp(MyApp());+ 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 theexample folder.
Here is an example that displays this window:
Click to expand
import'package:flutter/material.dart';import'package:bitsdojo_window/bitsdojo_window.dart';voidmain() {runApp(constMyApp());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);classMyAppextendsStatelessWidget {constMyApp({Key? key}):super(key: key);@overrideWidgetbuild(BuildContext context) {returnMaterialApp( debugShowCheckedModeBanner:false, home:Scaffold( body:WindowBorder( color: borderColor, width:1, child:Row( children:const [LeftSide(),RightSide()], ), ), ), ); }}const sidebarColor=Color(0xFFF6A00C);classLeftSideextendsStatelessWidget {constLeftSide({Key? key}):super(key: key);@overrideWidgetbuild(BuildContext context) {returnSizedBox( width:200, child:Container( color: sidebarColor, child:Column( children: [WindowTitleBarBox(child:MoveWindow()),Expanded(child:Container()) ], ))); }}const backgroundStartColor=Color(0xFFFFD500);const backgroundEndColor=Color(0xFFF6A00C);classRightSideextendsStatelessWidget {constRightSide({Key? key}):super(key: key);@overrideWidgetbuild(BuildContext context) {returnExpanded( child:Container( decoration:constBoxDecoration( 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()),constWindowButtons()], ), ) ]), ), ); }}final buttonColors=WindowButtonColors( iconNormal:constColor(0xFF805306), mouseOver:constColor(0xFFF6A00C), mouseDown:constColor(0xFF805306), iconMouseOver:constColor(0xFF805306), iconMouseDown:constColor(0xFFFFD500));final closeButtonColors=WindowButtonColors( mouseOver:constColor(0xFFD32F2F), mouseDown:constColor(0xFFB71C1C), iconNormal:constColor(0xFF805306), iconMouseOver:Colors.white);classWindowButtonsextendsStatelessWidget {constWindowButtons({Key? key}):super(key: key);@overrideWidgetbuild(BuildContext context) {returnRow( children: [MinimizeWindowButton(colors: buttonColors),MaximizeWindowButton(colors: buttonColors),CloseWindowButton(colors: closeButtonColors), ], ); }}
I am developing this package in my spare time and any help is appreciated.
If you want to help you canbecome a sponsor.
🙏 Thank you!
No sponsors
About
A Flutter package that makes it easy to customize and work with your Flutter desktop app window.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Contributors13
Uh oh!
There was an error while loading.Please reload this page.

