Skip to content

Commit 2f53942

Browse files
Window Manager fix for Linux (#44)
* Fix "No method isFocused" error for Linux Flet client Fix #42 * AppBar.elevation added Fix #43 * window_manager 0.2.5
1 parent 0e617fe commit 2f53942

File tree

10 files changed

+49
-5
lines changed

10 files changed

+49
-5
lines changed

client/lib/controls/app_bar.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AppBarControl extends StatelessWidget implements PreferredSizeWidget {
3232
var actionCtrls = children.where((c) => c.name == "action" && c.isVisible);
3333

3434
var leadingWidth = control.attrDouble("leadingWidth");
35+
var elevation = control.attrDouble("elevation");
3536
var centerTitle = control.attrBool("centerTitle", false)!;
3637
var color = HexColor.fromString(theme, control.attrString("color", "")!);
3738
var bgcolor =
@@ -49,6 +50,7 @@ class AppBarControl extends StatelessWidget implements PreferredSizeWidget {
4950
toolbarHeight: preferredSize.height,
5051
foregroundColor: color,
5152
backgroundColor: bgcolor,
53+
elevation: elevation,
5254
actions: actionCtrls
5355
.map((c) => createControl(control, c.id, control.isDisabled))
5456
.toList(),

client/lib/utils/desktop.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,17 @@ Future unmaximizeWindow() async {
111111
}
112112

113113
Future focusWindow() async {
114-
if (isDesktop() && !await windowManager.isFocused()) {
114+
if (isDesktop() &&
115+
(Platform.isWindows || Platform.isMacOS) &&
116+
!await windowManager.isFocused()) {
115117
await windowManager.focus();
116118
}
117119
}
118120

119121
Future blurWindow() async {
120-
if (isDesktop() && await windowManager.isFocused()) {
122+
if (isDesktop() &&
123+
(Platform.isWindows || Platform.isMacOS) &&
124+
await windowManager.isFocused()) {
121125
await windowManager.blur();
122126
}
123127
}
@@ -134,12 +138,20 @@ Future centerWindow() async {
134138
}
135139
}
136140

141+
Future isFocused() async {
142+
if (isDesktop() && (Platform.isWindows || Platform.isMacOS)) {
143+
return await windowManager.isFocused();
144+
} else {
145+
return false;
146+
}
147+
}
148+
137149
Future<WindowMediaData> getWindowMediaData() async {
138150
var m = WindowMediaData();
139151
if (isDesktop()) {
140152
m.isMaximized = await windowManager.isMaximized();
141153
m.isMinimized = await windowManager.isMinimized();
142-
m.isFocused = await windowManager.isFocused();
154+
m.isFocused = await isFocused();
143155
m.isTitleBarHidden = false;
144156
var size = await windowManager.getSize();
145157
m.width = size.width;

client/linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <screen_retriever/screen_retriever_plugin.h>
910
#include <window_manager/window_manager_plugin.h>
1011

1112
void fl_register_plugins(FlPluginRegistry* registry) {
13+
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
14+
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
15+
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
1216
g_autoptr(FlPluginRegistrar) window_manager_registrar =
1317
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
1418
window_manager_plugin_register_with_registrar(window_manager_registrar);

client/linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
screen_retriever
67
window_manager
78
)
89

client/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import FlutterMacOS
66
import Foundation
77

8+
import screen_retriever
89
import window_manager
910

1011
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
12+
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
1113
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
1214
}

client/pubspec.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ packages:
186186
url: "https://pub.dartlang.org"
187187
source: hosted
188188
version: "5.0.0"
189+
screen_retriever:
190+
dependency: transitive
191+
description:
192+
name: screen_retriever
193+
url: "https://pub.dartlang.org"
194+
source: hosted
195+
version: "0.1.2"
189196
sky_engine:
190197
dependency: transitive
191198
description: flutter
@@ -260,7 +267,7 @@ packages:
260267
name: window_manager
261268
url: "https://pub.dartlang.org"
262269
source: hosted
263-
version: "0.2.1"
270+
version: "0.2.5"
264271
xml:
265272
dependency: transitive
266273
description:

client/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies:
3737
flutter_redux: ^0.10.0
3838
equatable: ^2.0.3
3939
web_socket_channel: ^2.1.0
40-
window_manager: ^0.2.1
40+
window_manager: ^0.2.5
4141
http: ^0.13.3
4242

4343
dev_dependencies:

client/windows/flutter/generated_plugin_registrant.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <screen_retriever/screen_retriever_plugin.h>
910
#include <window_manager/window_manager_plugin.h>
1011

1112
void RegisterPlugins(flutter::PluginRegistry* registry) {
13+
ScreenRetrieverPluginRegisterWithRegistrar(
14+
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
1215
WindowManagerPluginRegisterWithRegistrar(
1316
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
1417
}

client/windows/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
screen_retriever
67
window_manager
78
)
89

sdk/python/flet/app_bar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(
1818
toolbar_height: OptionalNumber = None,
1919
color: str = None,
2020
bgcolor: str = None,
21+
elevation: OptionalNumber = None,
2122
actions: List[Control] = None,
2223
):
2324
Control.__init__(self, ref=ref)
@@ -33,6 +34,7 @@ def __init__(
3334
self.toolbar_height = toolbar_height
3435
self.color = color
3536
self.bgcolor = bgcolor
37+
self.elevation = elevation
3638
self.actions = actions
3739

3840
def _get_control_name(self):
@@ -119,6 +121,16 @@ def bgcolor(self):
119121
def bgcolor(self, value):
120122
self._set_attr("bgcolor", value)
121123

124+
# elevation
125+
@property
126+
def elevation(self) -> OptionalNumber:
127+
return self._get_attr("elevation")
128+
129+
@elevation.setter
130+
@beartype
131+
def elevation(self, value: OptionalNumber):
132+
self._set_attr("elevation", value)
133+
122134
# actions
123135
@property
124136
def actions(self):

0 commit comments

Comments
 (0)