Skip to content

Commit 2ff7e88

Browse files
Added InAppWebView widget MacOS support
1 parent ca417f8 commit 2ff7e88

File tree

7 files changed

+43
-44
lines changed

7 files changed

+43
-44
lines changed

flutter_inappwebview/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
## 6.1.0
22

33
- Added initial Windows support
4+
- Added `InAppWebView` MacOS support
45
- Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.
6+
- Updated androidx.webkit:webkit:1.8.0 to androidx.webkit:webkit:1.12.0
7+
- Updated androidx.browser:browser:1.6.0 to androidx.browser:browser:1.8.0
8+
- Fixed "[MACOS] launching InAppBrowser with 'hidden: true' calls onExit immediately" [#1939](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1939)
9+
- Fixed XCode 16 build
10+
- Removed unsupported WebViewFeature.SUPPRESS_ERROR_PAGE
511

612
## 6.0.0
713

flutter_inappwebview/example/lib/main.dart

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,18 @@ PointerInterceptor myDrawer({required BuildContext context}) {
8484
];
8585
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
8686
children = [
87-
// ListTile(
88-
// title: Text('InAppWebView'),
89-
// onTap: () {
90-
// Navigator.pushReplacementNamed(context, '/');
91-
// },
92-
// ),
93-
// ListTile(
94-
// title: Text('InAppBrowser'),
95-
// onTap: () {
96-
// Navigator.pushReplacementNamed(context, '/InAppBrowser');
97-
// },
98-
// ),
9987
ListTile(
100-
title: Text('InAppBrowser'),
88+
title: Text('InAppWebView'),
10189
onTap: () {
10290
Navigator.pushReplacementNamed(context, '/');
10391
},
10492
),
93+
ListTile(
94+
title: Text('InAppBrowser'),
95+
onTap: () {
96+
Navigator.pushReplacementNamed(context, '/InAppBrowser');
97+
},
98+
),
10599
ListTile(
106100
title: Text('WebAuthenticationSession'),
107101
onTap: () {
@@ -181,9 +175,8 @@ class _MyAppState extends State<MyApp> {
181175
}
182176
if (defaultTargetPlatform == TargetPlatform.macOS) {
183177
return MaterialApp(initialRoute: '/', routes: {
184-
// '/': (context) => InAppWebViewExampleScreen(),
185-
// '/InAppBrowser': (context) => InAppBrowserExampleScreen(),
186-
'/': (context) => InAppBrowserExampleScreen(),
178+
'/': (context) => InAppWebViewExampleScreen(),
179+
'/InAppBrowser': (context) => InAppBrowserExampleScreen(),
187180
'/HeadlessInAppWebView': (context) =>
188181
HeadlessInAppWebViewExampleScreen(),
189182
'/WebAuthenticationSession': (context) =>

flutter_inappwebview_macos/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## 1.1.0
22

3+
- Added `InAppWebView` support
4+
- Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.
35
- Fixed "[MACOS] launching InAppBrowser with 'hidden: true' calls onExit immediately" [#1939](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1939)
46
- Fixed XCode 16 build
5-
- Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.
67

78
## 1.0.11
89

flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class MacOSInAppWebViewWidget extends PlatformInAppWebViewWidget {
300300
}
301301
}
302302

303-
return UiKitView(
303+
return AppKitView(
304304
viewType: 'com.pichillilorenzo/flutter_inappwebview',
305305
onPlatformViewCreated: _onPlatformViewCreated,
306306
gestureRecognizers: params.gestureRecognizers,

flutter_inappwebview_macos/lib/src/inappwebview_platform.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@ class MacOSInAppWebViewPlatform extends InAppWebViewPlatform {
4848
return MacOSInAppWebViewController.static();
4949
}
5050

51-
// TODO: unhide when Flutter official PlatformView for macOS is available
52-
// /// Creates a new [MacOSInAppWebViewWidget].
53-
// ///
54-
// /// This function should only be called by the app-facing package.
55-
// /// Look at using [InAppWebView] in `flutter_inappwebview` instead.
56-
// @override
57-
// MacOSInAppWebViewWidget createPlatformInAppWebViewWidget(
58-
// PlatformInAppWebViewWidgetCreationParams params,
59-
// ) {
60-
// return MacOSInAppWebViewWidget(params);
61-
// }
51+
/// Creates a new [MacOSInAppWebViewWidget].
52+
///
53+
/// This function should only be called by the app-facing package.
54+
/// Look at using [InAppWebView] in `flutter_inappwebview` instead.
55+
@override
56+
MacOSInAppWebViewWidget createPlatformInAppWebViewWidget(
57+
PlatformInAppWebViewWidgetCreationParams params,
58+
) {
59+
return MacOSInAppWebViewWidget(params);
60+
}
6261

6362
/// Creates a new [MacOSFindInteractionController].
6463
///

flutter_inappwebview_macos/macos/Classes/InAppWebView/FlutterWebViewController.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ import Foundation
99
import WebKit
1010
import FlutterMacOS
1111

12-
public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Disposable {
12+
public class FlutterWebViewController: NSView, Disposable {
1313

14-
var myView: NSView?
1514
var keepAliveId: String?
1615

1716
init(plugin: InAppWebViewFlutterPlugin, withFrame frame: CGRect, viewIdentifier viewId: Any, params: NSDictionary) {
18-
super.init()
19-
20-
myView = NSView(frame: frame)
17+
super.init(frame: frame)
2118

2219
keepAliveId = params["keepAliveId"] as? String
2320

@@ -47,12 +44,12 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
4744
binaryMessenger: registrar.messenger)
4845
webView!.channelDelegate = WebViewChannelDelegate(webView: webView!, channel: channel)
4946
}
50-
webView!.frame = myView!.bounds
47+
webView!.frame = self.bounds
5148
webView!.initialUserScripts = userScripts
5249
} else {
5350
webView = InAppWebView(id: viewId,
5451
plugin: plugin,
55-
frame: myView!.bounds,
52+
frame: self.bounds,
5653
configuration: preWebviewConfiguration,
5754
userScripts: userScripts)
5855
}
@@ -64,17 +61,21 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
6461
findInteractionController.prepare()
6562

6663
webView!.autoresizingMask = [.width, .height]
67-
myView!.autoresizesSubviews = true
68-
myView!.autoresizingMask = [.width, .height]
69-
myView!.addSubview(webView!)
64+
self.autoresizesSubviews = true
65+
self.autoresizingMask = [.width, .height]
66+
self.addSubview(webView!)
7067

7168
webView!.settings = settings
7269
webView!.prepare()
7370
webView!.windowCreated = true
7471
}
7572

73+
required init?(coder nsCoder: NSCoder) {
74+
super.init(coder: nsCoder)
75+
}
76+
7677
public func webView() -> InAppWebView? {
77-
for subview in myView?.subviews ?? []
78+
for subview in self.subviews
7879
{
7980
if let item = subview as? InAppWebView
8081
{
@@ -85,7 +86,7 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
8586
}
8687

8788
public func view() -> NSView {
88-
return myView!
89+
return self
8990
}
9091

9192
public func makeInitialLoad(params: NSDictionary) {
@@ -185,9 +186,8 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
185186
}
186187
}
187188
if removeFromSuperview {
188-
myView?.removeFromSuperview()
189+
self.removeFromSuperview()
189190
}
190-
myView = nil
191191
}
192192
}
193193

flutter_inappwebview_macos/macos/Classes/InAppWebView/FlutterWebViewFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public class FlutterWebViewFactory: NSObject, FlutterPlatformViewFactory {
6767
flutterWebView?.makeInitialLoad(params: arguments!)
6868
}
6969

70-
return flutterWebView!.view()
70+
return flutterWebView!
7171
}
7272
}

0 commit comments

Comments
 (0)