Skip to content

Commit 139320c

Browse files
committed
Let windowing.dart compile for the web
flutter_window.dart imports dart:ffi and the platform window controllers, so importing package:nativeapi_flutter/windowing.dart still broke a web build after the nativeapi web mirror. windowing.dart now exports a web version if (dart.library.js_interop) whose nativeWindowOf returns null, as documented for a controller with no window handle. The contentInset extension is plain Dart and moves to its own file, shared by both.
1 parent ce649a2 commit 139320c

5 files changed

Lines changed: 43 additions & 15 deletions

File tree

‎bindings/dart/nativeapi_flutter/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 0.4.1
22

3+
* `package:nativeapi_flutter/windowing.dart` compiles for the web too
4+
(leanflutter/tray_manager#108): there `nativeWindowOf` and `nativeWindow`
5+
return null, since no native window stands behind a controller.
6+
37
* `DragToMoveArea` follows the macOS title-bar double-click preference,
48
including Minimize and None, through the native window action.
59

‎bindings/dart/nativeapi_flutter/lib/src/windowing/flutter_window.dart‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ignore_for_file: invalid_use_of_internal_member, implementation_imports
22

33
import 'dart:ffi' as ffi;
4-
import 'dart:ui' show Offset;
54

65
import 'package:flutter/src/widgets/_window.dart' as fw;
76
import 'package:flutter/src/widgets/_window_linux.dart' as fw_linux;
@@ -10,8 +9,6 @@ import 'package:flutter/src/widgets/_window_win32.dart' as fw_win32;
109

1110
import 'package:nativeapi/nativeapi.dart' show Window;
1211

13-
import '../conversions.dart';
14-
1512
/// The native window behind a Flutter window controller, as a nativeapi
1613
/// [Window].
1714
///
@@ -44,14 +41,3 @@ extension FlutterWindowControllerNativeWindow on fw.BaseWindowController {
4441
/// Shorthand for [nativeWindowOf].
4542
Window? get nativeWindow => nativeWindowOf(this);
4643
}
47-
48-
extension NativeWindowGeometry on Window {
49-
/// Offset from the window's outer frame to its content area (title bar and
50-
/// left border), in logical pixels.
51-
///
52-
/// `WindowDragSession` anchors on the frame while Flutter reports positions
53-
/// inside the content, so an anchor derived from a pointer position needs
54-
/// this added.
55-
Offset get contentInset =>
56-
contentBounds.toRect().topLeft - bounds.toRect().topLeft;
57-
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ignore_for_file: invalid_use_of_internal_member, implementation_imports
2+
3+
import 'package:flutter/src/widgets/_window.dart' as fw;
4+
5+
import 'package:nativeapi/nativeapi.dart' show Window;
6+
7+
/// The native window behind a Flutter window controller, as a nativeapi
8+
/// [Window].
9+
///
10+
/// Always null on the web: there is no native window behind a controller, and
11+
/// the platform implementations (and `dart:ffi`) do not exist there.
12+
Window? nativeWindowOf(fw.BaseWindowController controller) => null;
13+
14+
extension FlutterWindowControllerNativeWindow on fw.BaseWindowController {
15+
/// Shorthand for [nativeWindowOf].
16+
Window? get nativeWindow => nativeWindowOf(this);
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'dart:ui' show Offset;
2+
3+
import 'package:nativeapi/nativeapi.dart' show Window;
4+
5+
import '../conversions.dart';
6+
7+
extension NativeWindowGeometry on Window {
8+
/// Offset from the window's outer frame to its content area (title bar and
9+
/// left border), in logical pixels.
10+
///
11+
/// `WindowDragSession` anchors on the frame while Flutter reports positions
12+
/// inside the content, so an anchor derived from a pointer position needs
13+
/// this added.
14+
Offset get contentInset =>
15+
contentBounds.toRect().topLeft - bounds.toRect().topLeft;
16+
}

‎bindings/dart/nativeapi_flutter/lib/windowing.dart‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
/// The stable channel does not offer `flutter config --enable-windowing`: an app
99
/// sets `isWindowingEnabled = true` (from
1010
/// `package:flutter/src/foundation/_features.dart`) before its binding starts.
11+
///
12+
/// On the web, where there are no native windows, [nativeWindowOf] returns
13+
/// null, so an app that also targets the web can still import this library.
1114
library;
1215

13-
export 'src/windowing/flutter_window.dart';
16+
export 'src/windowing/flutter_window.dart'
17+
if (dart.library.js_interop) 'src/windowing/flutter_window_web.dart';
18+
export 'src/windowing/window_geometry.dart';

0 commit comments

Comments
 (0)