From e02b5e0603719ff32f83cf6a78c5a84fc4545d51 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Halil=20G=C3=B6cer?=
Date: Wed, 2 Mar 2022 22:10:03 +0100
Subject: [PATCH 01/12] fix ios methods not returning
---
.../SwiftPresentationDisplaysPlugin.swift | 114 +++++++++---------
1 file changed, 59 insertions(+), 55 deletions(-)
diff --git a/ios/Classes/SwiftPresentationDisplaysPlugin.swift b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
index 7c23107..fd890d9 100644
--- a/ios/Classes/SwiftPresentationDisplaysPlugin.swift
+++ b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
@@ -14,7 +14,7 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
NotificationCenter.default.addObserver(forName: UIScreen.didConnectNotification,
object: nil, queue: nil) {
notification in
-
+
// Get the new screen information.
let newScreen = notification.object as! UIScreen
@@ -26,10 +26,10 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
// Configure a window for the screen.
let newWindow = UIWindow(frame: screenDimensions)
newWindow.screen = newScreen
-
+
// You must show the window explicitly.
newWindow.isHidden = true
-
+
// Save a reference to the window in a local array.
self.screens.append(newScreen)
self.additionalWindows[newScreen]=newWindow
@@ -37,21 +37,21 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
}
NotificationCenter.default.addObserver(forName:
- UIScreen.didDisconnectNotification,
+ UIScreen.didDisconnectNotification,
object: nil,
queue: nil) { notification in
- let screen = notification.object as! UIScreen
-
- // Remove the window associated with the screen.
+ let screen = notification.object as! UIScreen
+
+ // Remove the window associated with the screen.
for s in self.screens {
- if s == screen {
-
- let index = self.screens.index(of: s)
- self.screens.remove(at: index!)
- // Remove the window and its contents.
- self.additionalWindows.removeValue(forKey: s)
+ if s == screen {
+
+ let index = self.screens.index(of: s)
+ self.screens.remove(at: index!)
+ // Remove the window and its contents.
+ self.additionalWindows.removeValue(forKey: s)
+ }
}
- }
}
}
@@ -61,7 +61,7 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
registrar.addMethodCallDelegate(instance, channel: channel)
}
-
+
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// result("iOS " + UIDevice.current.systemVersion)
if call.method=="listDisplay"
@@ -71,7 +71,7 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
for i in 0..
- {
- print(json)
- showPresentation(index:json["displayId"] as? Int ?? 1, routerName: json["routerName"] as? String ?? "presentation")
- }
- else {
- print("bad json")
- }
+ do {
+ if let json = try JSONSerialization.jsonObject(with: data ?? Data(), options : .allowFragments) as? Dictionary
+ {
+ print(json)
+ showPresentation(index:json["displayId"] as? Int ?? 1, routerName: json["routerName"] as? String ?? "presentation")
+ result(true)
}
- catch let error as NSError {
- print(error)
- }
- }
- else if call.method=="transferDataToPresentation"{
- self.flutterEngineChannel.invokeMethod("DataTransfer", arguments: call.arguments)
+ else {
+ print("bad json")
+ result(false)
}
- else
- {
- result(FlutterMethodNotImplemented)
}
-
+ catch let error as NSError {
+ print(error)
+ result(false)
+ }
}
-
- private func showPresentation(index:Int, routerName:String )
+ else if call.method=="transferDataToPresentation"{
+ self.flutterEngineChannel.invokeMethod("DataTransfer", arguments: call.arguments)
+ result(true)
+ }
+ else
{
- if index>0 && index < self.screens.count && self.additionalWindows.keys.contains(self.screens[index])
- {
- let screen=self.screens[index]
- let window=self.additionalWindows[screen]
-
- // You must show the window explicitly.
- window?.isHidden=false
-
- let extVC = FlutterViewController()
- SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
- extVC.setInitialRoute(routerName)
- window?.rootViewController = extVC
-
-
- self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
- }
-
+ result(FlutterMethodNotImplemented)
}
-
+
}
+
+ private func showPresentation(index:Int, routerName:String )
+ {
+ if index>0 && index < self.screens.count && self.additionalWindows.keys.contains(self.screens[index])
+ {
+ let screen=self.screens[index]
+ let window=self.additionalWindows[screen]
+
+ // You must show the window explicitly.
+ window?.isHidden=false
+
+ let extVC = FlutterViewController()
+ SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
+ extVC.setInitialRoute(routerName)
+ window?.rootViewController = extVC
+
+
+ self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
+ }
+
+ }
+
+}
From fdd761fdb337b8fe2f80dc0796ff27c13edf34fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Halil=20G=C3=B6cer?=
Date: Wed, 2 Mar 2022 22:30:45 +0100
Subject: [PATCH 02/12] ios: add display (dis-)/connected events
---
.../SwiftPresentationDisplaysPlugin.swift | 37 ++++++++++++++++++-
lib/displays_manager.dart | 21 ++++++++---
2 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/ios/Classes/SwiftPresentationDisplaysPlugin.swift b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
index fd890d9..3e88eeb 100644
--- a/ios/Classes/SwiftPresentationDisplaysPlugin.swift
+++ b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
@@ -60,11 +60,14 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
let instance = SwiftPresentationDisplaysPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
+ let eventChannel = FlutterEventChannel(name: "presentation_displays_plugin_events", binaryMessenger: registrar.messenger())
+ let displayConnectedStreamHandler = DisplayConnectedStreamHandler()
+ eventChannel.setStreamHandler(displayConnectedStreamHandler)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// result("iOS " + UIDevice.current.systemVersion)
- if call.method=="listDisplay"
+ if call.method=="listDisplay"
{
var jsonDisplaysList:String = "[";
let screensList = self.screens
@@ -131,3 +134,35 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
}
}
+
+class DisplayConnectedStreamHandler: NSObject, FlutterStreamHandler{
+ var sink: FlutterEventSink?
+ var didConnectObserver: NSObjectProtocol?
+ var didDisconnectObserver: NSObjectProtocol?
+
+ func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
+ sink = events
+ didConnectObserver = NotificationCenter.default.addObserver(forName: UIScreen.didConnectNotification,
+ object: nil, queue: nil) { (notification) in
+ guard let sink = self.sink else { return }
+ sink(1)
+ }
+ didDisconnectObserver = NotificationCenter.default.addObserver(forName: UIScreen.didDisconnectNotification,
+ object: nil, queue: nil) { (notification) in
+ guard let sink = self.sink else { return }
+ sink(0)
+ }
+ return nil
+ }
+
+ func onCancel(withArguments arguments: Any?) -> FlutterError? {
+ sink = nil
+ if (didConnectObserver != nil){
+ NotificationCenter.default.removeObserver(didConnectObserver!)
+ }
+ if (didDisconnectObserver != nil){
+ NotificationCenter.default.removeObserver(didDisconnectObserver!)
+ }
+ return nil
+ }
+}
diff --git a/lib/displays_manager.dart b/lib/displays_manager.dart
index b9720f3..612b4c0 100644
--- a/lib/displays_manager.dart
+++ b/lib/displays_manager.dart
@@ -31,11 +31,14 @@ const String DISPLAY_CATEGORY_PRESENTATION =
/// Provide you with the method for you to work with [SecondaryDisplay].
class DisplayManager {
- final _displayChannel = "presentation_displays_plugin";
- MethodChannel? _displayMethodChannel;
+ final _displayMethodChannelId = "presentation_displays_plugin";
+ final _displayEventChannelId = "presentation_displays_plugin_events";
+ late MethodChannel _displayMethodChannel;
+ late EventChannel _displayEventChannel;
DisplayManager() {
- _displayMethodChannel = MethodChannel(_displayChannel);
+ _displayMethodChannel = MethodChannel(_displayMethodChannelId);
+ _displayEventChannel = EventChannel(_displayEventChannelId);
}
/// Gets all currently valid logical displays of the specified category.
@@ -54,7 +57,7 @@ class DisplayManager {
/// See [DISPLAY_CATEGORY_PRESENTATION]
FutureOr?> getDisplays({String? category}) async {
List origins = await jsonDecode(await _displayMethodChannel
- ?.invokeMethod(_listDisplay, category)) ??
+ .invokeMethod(_listDisplay, category)) ??
[];
List displays = [];
origins.forEach((element) {
@@ -110,7 +113,7 @@ class DisplayManager {
/// return [Future] about the status has been display or not
Future? showSecondaryDisplay(
{required int displayId, required String routerName}) {
- return _displayMethodChannel?.invokeMethod(
+ return _displayMethodChannel.invokeMethod(
_showPresentation,
"{"
"\"displayId\": $displayId,"
@@ -171,7 +174,13 @@ class DisplayManager {
///
/// return [Future] the value to determine whether or not the data has been transferred successfully
Future? transferDataToPresentation(dynamic arguments) {
- return _displayMethodChannel?.invokeMethod(
+ return _displayMethodChannel.invokeMethod(
_transferDataToPresentation, arguments);
}
+
+ /// Subscribe to the stream to get notifications about connected / disconnected displays
+ /// Streams [1] for new connected display and [0] for disconnected display
+ Stream get connectedDisplaysChangedStream {
+ return _displayEventChannel.receiveBroadcastStream().cast();
+ }
}
From 4c76f0a2aefa29ba81566b1f77e02fc8f60018ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Halil=20G=C3=B6cer?=
Date: Wed, 2 Mar 2022 22:53:54 +0100
Subject: [PATCH 03/12] ios: add hide presentation
---
.../SwiftPresentationDisplaysPlugin.swift | 46 ++++++++++++++++---
lib/displays_manager.dart | 16 +++++++
2 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/ios/Classes/SwiftPresentationDisplaysPlugin.swift b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
index 3e88eeb..f7160a1 100644
--- a/ios/Classes/SwiftPresentationDisplaysPlugin.swift
+++ b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
@@ -4,7 +4,7 @@ import UIKit
public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
var additionalWindows = [UIScreen:UIWindow]()
var screens = [UIScreen]()
- var flutterEngineChannel:FlutterMethodChannel=FlutterMethodChannel()
+ var flutterEngineChannel:FlutterMethodChannel?=nil
public static var controllerAdded: ((FlutterViewController)->Void)?
public override init() {
@@ -46,7 +46,7 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
for s in self.screens {
if s == screen {
- let index = self.screens.index(of: s)
+ let index = self.screens.firstIndex(of: s)
self.screens.remove(at: index!)
// Remove the window and its contents.
self.additionalWindows.removeValue(forKey: s)
@@ -66,7 +66,6 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
- // result("iOS " + UIDevice.current.systemVersion)
if call.method=="listDisplay"
{
var jsonDisplaysList:String = "[";
@@ -101,8 +100,28 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
result(false)
}
}
+ else if call.method=="hidePresentation"{
+ let args = call.arguments as? String
+ let data = args?.data(using: .utf8)!
+ do {
+ if let json = try JSONSerialization.jsonObject(with: data ?? Data(), options : .allowFragments) as? Dictionary
+ {
+ print(json)
+ hidePresentation(index:json["displayId"] as? Int ?? 1)
+ result(true)
+ }
+ else {
+ print("bad json")
+ result(false)
+ }
+ }
+ catch let error as NSError {
+ print(error)
+ result(false)
+ }
+ }
else if call.method=="transferDataToPresentation"{
- self.flutterEngineChannel.invokeMethod("DataTransfer", arguments: call.arguments)
+ self.flutterEngineChannel?.invokeMethod("DataTransfer", arguments: call.arguments)
result(true)
}
else
@@ -112,7 +131,7 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
}
- private func showPresentation(index:Int, routerName:String )
+ private func showPresentation(index:Int, routerName:String )
{
if index>0 && index < self.screens.count && self.additionalWindows.keys.contains(self.screens[index])
{
@@ -122,14 +141,27 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
// You must show the window explicitly.
window?.isHidden=false
- let extVC = FlutterViewController()
+ let extVC = FlutterViewController(project: nil, initialRoute: routerName, nibName: nil, bundle: nil)
SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
- extVC.setInitialRoute(routerName)
window?.rootViewController = extVC
self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
}
+ }
+
+ private func hidePresentation(index:Int)
+ {
+ if index>0 && index < self.screens.count && self.additionalWindows.keys.contains(self.screens[index])
+ {
+ let screen=self.screens[index]
+ let window=self.additionalWindows[screen]
+
+ window?.rootViewController = nil
+ window?.isHidden=true
+
+ self.flutterEngineChannel = nil
+ }
}
diff --git a/lib/displays_manager.dart b/lib/displays_manager.dart
index 612b4c0..ca52ada 100644
--- a/lib/displays_manager.dart
+++ b/lib/displays_manager.dart
@@ -8,6 +8,7 @@ import 'package:presentation_displays/secondary_display.dart';
const _listDisplay = "listDisplay";
const _showPresentation = "showPresentation";
+const _hidePresentation = "hidePresentation";
const _transferDataToPresentation = "transferDataToPresentation";
/// Display category: secondary display.
@@ -121,6 +122,21 @@ class DisplayManager {
"}");
}
+ /// Hides secondary display that is attached to the specified display
+ ///
+ /// [displayId] The id of display to which the secondary display should be attached.
+ ///
+ ///
+ /// return [Future] about the status has been display or not
+ Future? hideSecondaryDisplay(
+ {required int displayId}) {
+ return _displayMethodChannel.invokeMethod(
+ _hidePresentation,
+ "{"
+ "\"displayId\": $displayId"
+ "}");
+ }
+
/// Transfer data to a secondary display
///
/// Transfer data from main screen to a secondary display
From 65bc999afcff2a55414f9b53bc4f3ad459ab7133 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Halil=20G=C3=B6cer?=
Date: Wed, 2 Mar 2022 23:03:58 +0100
Subject: [PATCH 04/12] workspace changes
---
example/ios/Flutter/AppFrameworkInfo.plist | 2 +-
example/ios/Podfile.lock | 22 +++++
example/ios/Runner.xcodeproj/project.pbxproj | 96 ++++++++++++++++---
.../contents.xcworkspacedata | 2 +-
.../xcshareddata/xcschemes/Runner.xcscheme | 2 +-
.../contents.xcworkspacedata | 3 +
example/pubspec.lock | 18 ++--
pubspec.lock | 16 ++--
8 files changed, 130 insertions(+), 31 deletions(-)
create mode 100644 example/ios/Podfile.lock
diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist
index 6b4c0f7..f2872cf 100644
--- a/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/example/ios/Flutter/AppFrameworkInfo.plist
@@ -21,6 +21,6 @@
CFBundleVersion
1.0
MinimumOSVersion
- 8.0
+ 9.0
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
new file mode 100644
index 0000000..5ee6348
--- /dev/null
+++ b/example/ios/Podfile.lock
@@ -0,0 +1,22 @@
+PODS:
+ - Flutter (1.0.0)
+ - presentation_displays (0.0.1):
+ - Flutter
+
+DEPENDENCIES:
+ - Flutter (from `Flutter`)
+ - presentation_displays (from `.symlinks/plugins/presentation_displays/ios`)
+
+EXTERNAL SOURCES:
+ Flutter:
+ :path: Flutter
+ presentation_displays:
+ :path: ".symlinks/plugins/presentation_displays/ios"
+
+SPEC CHECKSUMS:
+ Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
+ presentation_displays: 02a9b05f708afe31d23564988f285b4d8019ddcd
+
+PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
+
+COCOAPODS: 1.10.2
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index 2e7bbca..47c8ee1 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 46;
+ objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
@@ -13,6 +13,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
+ DBAE77DD5D21C66D5647DD42 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0BB6A46A669E6E9DB5680B64 /* Pods_Runner.framework */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -29,12 +30,15 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 0BB6A46A669E6E9DB5680B64 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; };
+ 4A7A3DD543CBD0AC87B9CD6E /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; };
+ 7D838C0D41F8A35C27D4C46C /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -42,6 +46,7 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
+ C0599EA2B041B0EDE8716590 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -49,12 +54,24 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ DBAE77DD5D21C66D5647DD42 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ 624DAE587250BE9959AB91ED /* Pods */ = {
+ isa = PBXGroup;
+ children = (
+ 7D838C0D41F8A35C27D4C46C /* Pods-Runner.debug.xcconfig */,
+ 4A7A3DD543CBD0AC87B9CD6E /* Pods-Runner.release.xcconfig */,
+ C0599EA2B041B0EDE8716590 /* Pods-Runner.profile.xcconfig */,
+ );
+ name = Pods;
+ path = Pods;
+ sourceTree = "";
+ };
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
@@ -72,6 +89,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
+ 624DAE587250BE9959AB91ED /* Pods */,
+ B4DF188180DDF6A32C123F4B /* Frameworks */,
);
sourceTree = "";
};
@@ -106,6 +125,14 @@
name = "Supporting Files";
sourceTree = "";
};
+ B4DF188180DDF6A32C123F4B /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 0BB6A46A669E6E9DB5680B64 /* Pods_Runner.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -113,12 +140,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
+ 3A83F31962615BA318D35675 /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
+ A85E4277070E1E475E143A7B /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
@@ -135,7 +164,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 1020;
+ LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
@@ -177,6 +206,28 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
+ 3A83F31962615BA318D35675 /* [CP] Check Pods Manifest.lock */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputFileListPaths = (
+ );
+ inputPaths = (
+ "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
+ "${PODS_ROOT}/Manifest.lock",
+ );
+ name = "[CP] Check Pods Manifest.lock";
+ outputFileListPaths = (
+ );
+ outputPaths = (
+ "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
+ showEnvVarsInLog = 0;
+ };
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -205,6 +256,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
+ A85E4277070E1E475E143A7B /* [CP] Embed Pods Frameworks */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputFileListPaths = (
+ "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
+ );
+ name = "[CP] Embed Pods Frameworks";
+ outputFileListPaths = (
+ "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
+ showEnvVarsInLog = 0;
+ };
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -241,7 +309,6 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
@@ -281,7 +348,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -303,7 +370,10 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
@@ -318,7 +388,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
@@ -364,7 +433,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -374,7 +443,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
@@ -414,7 +482,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -437,7 +505,10 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
@@ -464,7 +535,10 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
index 1d526a1..919434a 100644
--- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -2,6 +2,6 @@
+ location = "self:">
diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
index a28140c..3db53b6 100644
--- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
+++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
@@ -1,6 +1,6 @@
+
+
diff --git a/example/pubspec.lock b/example/pubspec.lock
index c37cbae..d4a3b22 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.6.1"
+ version: "2.8.2"
boolean_selector:
dependency: transitive
description:
@@ -21,14 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
clock:
dependency: transitive
description:
@@ -73,14 +73,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.10"
+ version: "0.12.11"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
- version: "1.3.0"
+ version: "1.7.0"
path:
dependency: transitive
description:
@@ -101,7 +101,7 @@ packages:
path: ".."
relative: true
source: path
- version: "0.1.10"
+ version: "0.2.1"
sky_engine:
dependency: transitive
description: flutter
@@ -148,7 +148,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.3.0"
+ version: "0.4.3"
typed_data:
dependency: transitive
description:
@@ -162,7 +162,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
sdks:
- dart: ">=2.12.0 <3.0.0"
+ dart: ">=2.14.0 <3.0.0"
flutter: ">=1.12.0"
diff --git a/pubspec.lock b/pubspec.lock
index c72185d..eba04e0 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.6.1"
+ version: "2.8.2"
boolean_selector:
dependency: transitive
description:
@@ -21,14 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
clock:
dependency: transitive
description:
@@ -66,14 +66,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.10"
+ version: "0.12.11"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
- version: "1.3.0"
+ version: "1.7.0"
path:
dependency: transitive
description:
@@ -134,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.3.0"
+ version: "0.4.3"
typed_data:
dependency: transitive
description:
@@ -148,7 +148,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
sdks:
- dart: ">=2.12.0 <3.0.0"
+ dart: ">=2.14.0 <3.0.0"
flutter: ">=1.12.0"
From 4bd4f981a686640f7a9033cc4545829728fff487 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Halil=20G=C3=B6cer?=
Date: Wed, 2 Mar 2022 23:30:04 +0100
Subject: [PATCH 05/12] ios: fix hide screen
---
.../SwiftPresentationDisplaysPlugin.swift | 23 +++++++++----------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/ios/Classes/SwiftPresentationDisplaysPlugin.swift b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
index f7160a1..8a4240c 100644
--- a/ios/Classes/SwiftPresentationDisplaysPlugin.swift
+++ b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
@@ -138,15 +138,17 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
let screen=self.screens[index]
let window=self.additionalWindows[screen]
- // You must show the window explicitly.
- window?.isHidden=false
-
- let extVC = FlutterViewController(project: nil, initialRoute: routerName, nibName: nil, bundle: nil)
- SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
- window?.rootViewController = extVC
-
-
- self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
+ if (window != nil){
+ window!.isHidden=false
+ if (window!.rootViewController == nil || !(window!.rootViewController is FlutterViewController)){
+ let extVC = FlutterViewController(project: nil, initialRoute: routerName, nibName: nil, bundle: nil)
+ SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
+ window?.rootViewController = extVC
+
+
+ self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
+ }
+ }
}
}
@@ -157,10 +159,7 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
let screen=self.screens[index]
let window=self.additionalWindows[screen]
- window?.rootViewController = nil
window?.isHidden=true
-
- self.flutterEngineChannel = nil
}
}
From 80bd5cca94cf3f1eed8187a144c1b3c48a4a620f Mon Sep 17 00:00:00 2001
From: hig-dev
Date: Thu, 3 Mar 2022 06:26:15 +0100
Subject: [PATCH 06/12] android: implement display listener + hide presentation
---
.../PresentationDisplaysPlugin.kt | 69 +++++++++++++++++--
example/android/app/build.gradle | 2 +-
.../android/app/src/main/AndroidManifest.xml | 4 +-
.../MainActivity.kt | 6 --
example/android/build.gradle | 4 +-
.../gradle/wrapper/gradle-wrapper.properties | 2 +-
example/lib/main.dart | 8 +++
7 files changed, 77 insertions(+), 18 deletions(-)
delete mode 100644 example/android/app/src/main/kotlin/com/namit/presentation_displays_example/MainActivity.kt
diff --git a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
index b5f3e8f..b5d156d 100644
--- a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
+++ b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
@@ -3,6 +3,7 @@ package com.namit.presentation_displays
import android.content.ContentValues.TAG
import android.content.Context
import android.hardware.display.DisplayManager
+import android.os.Handler
import android.util.Log
import android.view.Display
import androidx.annotation.NonNull
@@ -13,6 +14,7 @@ import io.flutter.embedding.engine.dart.DartExecutor
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
+import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry
@@ -23,17 +25,25 @@ class PresentationDisplaysPlugin() : FlutterPlugin, ActivityAware, MethodChannel
private lateinit var channel : MethodChannel
+ private lateinit var eventChannel : EventChannel
private var flutterEngineChannel: MethodChannel? = null
- private var displayManager: DisplayManager? = null
private var context:Context?=null
+ private var presentationDisplay:PresentationDisplay?=null
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
- channel = MethodChannel(flutterPluginBinding.flutterEngine.dartExecutor, viewTypeId)
+ channel = MethodChannel(flutterPluginBinding.binaryMessenger, viewTypeId)
channel.setMethodCallHandler(this)
+
+ eventChannel = EventChannel(flutterPluginBinding.binaryMessenger, viewTypeEventsId)
+ displayManager = flutterPluginBinding.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ val displayConnectedStreamHandler = DisplayConnectedStreamHandler(displayManager)
+ eventChannel.setStreamHandler(displayConnectedStreamHandler)
}
companion object{
- private val viewTypeId = "presentation_displays_plugin"
+ private const val viewTypeId = "presentation_displays_plugin"
+ private const val viewTypeEventsId = "presentation_displays_plugin_events"
+ private var displayManager: DisplayManager? = null
/**
* @hide
@@ -42,11 +52,17 @@ class PresentationDisplaysPlugin() : FlutterPlugin, ActivityAware, MethodChannel
fun registerWith(registrar: PluginRegistry.Registrar) {
val channel = MethodChannel(registrar.messenger(), viewTypeId)
channel.setMethodCallHandler(PresentationDisplaysPlugin())
+
+ val eventChannel = EventChannel(registrar.messenger(), viewTypeEventsId)
+ displayManager = registrar.activity().getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ val displayConnectedStreamHandler = DisplayConnectedStreamHandler(displayManager)
+ eventChannel.setStreamHandler(displayConnectedStreamHandler)
}
}
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
+ eventChannel.setStreamHandler(null)
}
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
@@ -65,8 +81,8 @@ class PresentationDisplaysPlugin() : FlutterPlugin, ActivityAware, MethodChannel
if (display != null) {
flutterEngine?.let {
flutterEngineChannel = MethodChannel(it.dartExecutor.binaryMessenger, "${viewTypeId}_engine")
- val presentation = context?.let { it1 -> PresentationDisplay(it1, tag, display) }
- presentation?.show()
+ presentationDisplay = context?.let { it1 -> PresentationDisplay(it1, tag, display) }
+ presentationDisplay?.show()
result.success(true)
} ?: result.error("404", "Can't find FlutterEngine", null)
@@ -78,6 +94,18 @@ class PresentationDisplaysPlugin() : FlutterPlugin, ActivityAware, MethodChannel
result.error(call.method, e.message, null)
}
}
+ "hidePresentation" -> {
+ try {
+ val obj = JSONObject(call.arguments as String)
+ Log.i(TAG, "Channel: method: ${call.method} | displayId: ${obj.getInt("displayId")}")
+
+ presentationDisplay?.dismiss()
+ presentationDisplay = null
+ result.success(true)
+ } catch (e: Exception) {
+ result.error(call.method, e.message, null)
+ }
+ }
"listDisplay" -> {
val gson = Gson()
val category = call.arguments
@@ -127,9 +155,38 @@ class PresentationDisplaysPlugin() : FlutterPlugin, ActivityAware, MethodChannel
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.context = binding.activity
- this.displayManager = context?.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ displayManager = context?.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
}
override fun onDetachedFromActivityForConfigChanges() {
}
}
+
+class DisplayConnectedStreamHandler(private var displayManager: DisplayManager?) : EventChannel.StreamHandler {
+ private var sink: EventChannel.EventSink? = null
+ var handler: Handler? = null
+
+ private val displayListener = object : DisplayManager.DisplayListener {
+ override fun onDisplayAdded(displayId: Int) {
+ sink?.success(1)
+ }
+
+ override fun onDisplayRemoved(displayId: Int) {
+ sink?.success(0)
+ }
+
+ override fun onDisplayChanged(p0: Int) {}
+ }
+
+ override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
+ sink = events
+ handler = Handler()
+ displayManager?.registerDisplayListener(displayListener, handler)
+ }
+
+ override fun onCancel(arguments: Any?) {
+ sink = null
+ handler = null
+ displayManager?.unregisterDisplayListener(displayListener)
+ }
+}
diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle
index e1772e3..859c397 100644
--- a/example/android/app/build.gradle
+++ b/example/android/app/build.gradle
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
- compileSdkVersion 28
+ compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index 32eaf41..39ff77e 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -6,11 +6,11 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
{
TextEditingController _nameOfIndexController = TextEditingController();
String _nameOfIndex = "";
+ @override
+ void initState() {
+ displayManager.connectedDisplaysChangedStream.listen((event) {
+ debugPrint("connected displays changed: $event");
+ },);
+ super.initState();
+ }
+
@override
Widget build(BuildContext context) {
return Scaffold(
From 9db938b22ebf767eb50008938380936966e3d05a Mon Sep 17 00:00:00 2001
From: hig-dev
Date: Wed, 25 May 2022 20:33:31 +0200
Subject: [PATCH 07/12] Fix kotlin build error
---
.../PresentationDisplaysPlugin.kt | 2 +-
example/pubspec.lock | 25 +++++++------------
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
index 783a96a..b5fb014 100644
--- a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
+++ b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
@@ -54,7 +54,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
channel.setMethodCallHandler(PresentationDisplaysPlugin())
val eventChannel = EventChannel(registrar.messenger(), viewTypeEventsId)
- displayManager = registrar.activity().getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ displayManager = registrar.activity()!!.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val displayConnectedStreamHandler = DisplayConnectedStreamHandler(displayManager)
eventChannel.setStreamHandler(displayConnectedStreamHandler)
}
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 56e5676..2a930ad 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
- version: "1.15.0"
+ version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
@@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
@@ -94,7 +94,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
- version: "0.1.3"
+ version: "0.1.4"
meta:
dependency: transitive
description:
@@ -108,14 +108,14 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.0"
+ version: "1.8.1"
presentation_displays:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
- version: "0.2.2"
+ version: "0.2.3"
sky_engine:
dependency: transitive
description: flutter
@@ -127,7 +127,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.1"
+ version: "1.8.2"
stack_trace:
dependency: transitive
description:
@@ -162,21 +162,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.8"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
+ version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.1"
+ version: "2.1.2"
sdks:
- dart: ">=2.14.0 <3.0.0"
+ dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.10.3"
From bc30c72b933738c697c455eeed6e51a4e78491b3 Mon Sep 17 00:00:00 2001
From: hig-dev
Date: Thu, 26 May 2022 18:25:07 +0200
Subject: [PATCH 08/12] Fix merging mistakes
---
.../PresentationDisplaysPlugin.kt | 8 ++++----
.../SwiftPresentationDisplaysPlugin.swift | 20 +++++++++----------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
index b5fb014..088f102 100644
--- a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
+++ b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
@@ -28,7 +28,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
private lateinit var eventChannel : EventChannel
private var flutterEngineChannel: MethodChannel? = null
private var context:Context?=null
- private var presentationDisplay:PresentationDisplay?=null
+ private var presentation:PresentationDisplay?=null
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, viewTypeId)
@@ -87,7 +87,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
it.dartExecutor.binaryMessenger,
"${viewTypeId}_engine"
)
- val presentation =
+ presentation =
context?.let { it1 -> PresentationDisplay(it1, tag, display) }
Log.i(TAG, "presentation: $presentation")
presentation?.show()
@@ -105,8 +105,8 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
val obj = JSONObject(call.arguments as String)
Log.i(TAG, "Channel: method: ${call.method} | displayId: ${obj.getInt("displayId")}")
- presentationDisplay?.dismiss()
- presentationDisplay = null
+ presentation?.dismiss()
+ presentation = null
result.success(true)
} catch (e: Exception) {
result.error(call.method, e.message, null)
diff --git a/ios/Classes/SwiftPresentationDisplaysPlugin.swift b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
index 482bd40..90e66d6 100644
--- a/ios/Classes/SwiftPresentationDisplaysPlugin.swift
+++ b/ios/Classes/SwiftPresentationDisplaysPlugin.swift
@@ -4,7 +4,7 @@ import UIKit
public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
var additionalWindows = [UIScreen:UIWindow]()
var screens = [UIScreen]()
- var flutterEngineChannel:FlutterMethodChannel=FlutterMethodChannel()
+ var flutterEngineChannel:FlutterMethodChannel?=nil
public static var controllerAdded: ((FlutterViewController)->Void)?
public override init() {
@@ -134,15 +134,16 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
let screen=self.screens[index]
let window=self.additionalWindows[screen]
- // You must show the window explicitly.
- window?.isHidden=false
-
- let extVC = FlutterViewController()
- SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
- extVC.setInitialRoute(routerName)
- window?.rootViewController = extVC
+ if (window != nil){
+ window!.isHidden=false
+ if (window!.rootViewController == nil || !(window!.rootViewController is FlutterViewController)){
+ let extVC = FlutterViewController(project: nil, initialRoute: routerName, nibName: nil, bundle: nil)
+ SwiftPresentationDisplaysPlugin.controllerAdded!(extVC)
+ window?.rootViewController = extVC
- self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
+ self.flutterEngineChannel = FlutterMethodChannel(name: "presentation_displays_plugin_engine", binaryMessenger: extVC.binaryMessenger)
+ }
+ }
}
}
@@ -155,7 +156,6 @@ public class SwiftPresentationDisplaysPlugin: NSObject, FlutterPlugin {
window?.isHidden=true
}
-
}
}
From 5d46ec155b88f668fd802f210dbab10c2d96028a Mon Sep 17 00:00:00 2001
From: hig-dev
Date: Thu, 26 May 2022 18:25:23 +0200
Subject: [PATCH 09/12] Add hide display to example app
---
example/lib/main.dart | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/example/lib/main.dart b/example/lib/main.dart
index 0f66d16..5eb6102 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -99,6 +99,7 @@ class _DisplayManagerScreenState extends State {
children: [
_getDisplays(),
_showPresentation(),
+ _hidePresentation(),
_transferData(),
_getDisplayeById(),
_getDisplayByIndex(),
@@ -174,6 +175,39 @@ class _DisplayManagerScreenState extends State {
);
}
+ Widget _hidePresentation() {
+ return Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Padding(
+ padding: const EdgeInsets.all(8.0),
+ child: TextField(
+ controller: _indexToShareController,
+ decoration: const InputDecoration(
+ border: OutlineInputBorder(),
+ labelText: 'Index to hide screen',
+ ),
+ ),
+ ),
+ Button(
+ title: "Hide presentation",
+ onPressed: () async {
+ int? displayId = int.tryParse(_indexToShareController.text);
+ if (displayId != null) {
+ for (final display in displays) {
+ if (display?.displayId == displayId) {
+ displayManager.hideSecondaryDisplay(
+ displayId: displayId);
+ }
+ }
+ }
+ }),
+ const Divider(),
+ ],
+ );
+ }
+
Widget _transferData() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
From b6bbe5c7163679298340920f793c72814c40d611 Mon Sep 17 00:00:00 2001
From: hig-dev
Date: Thu, 26 May 2022 18:38:33 +0200
Subject: [PATCH 10/12] refactoring
---
.../presentation_displays/PresentationDisplaysPlugin.kt | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
index 088f102..9b1d9e2 100644
--- a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
+++ b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
@@ -4,10 +4,10 @@ import android.content.ContentValues.TAG
import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Handler
+import android.os.Looper
import android.util.Log
import android.view.Display
import androidx.annotation.NonNull
-import androidx.core.content.ContextCompat.getSystemService
import com.google.gson.Gson
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
@@ -48,6 +48,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
/**
* @hide
*/
+ @Suppress("unused", "DEPRECATION")
@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
val channel = MethodChannel(registrar.messenger(), viewTypeId)
@@ -174,7 +175,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
class DisplayConnectedStreamHandler(private var displayManager: DisplayManager?) : EventChannel.StreamHandler {
private var sink: EventChannel.EventSink? = null
- var handler: Handler? = null
+ private var handler: Handler? = null
private val displayListener = object : DisplayManager.DisplayListener {
override fun onDisplayAdded(displayId: Int) {
@@ -190,7 +191,7 @@ class DisplayConnectedStreamHandler(private var displayManager: DisplayManager?)
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
sink = events
- handler = Handler()
+ handler = Handler(Looper.getMainLooper())
displayManager?.registerDisplayListener(displayListener, handler)
}
From 330beac5b1b8903bd82864cd0267e9428294bce7 Mon Sep 17 00:00:00 2001
From: fuadreza
Date: Wed, 7 Jun 2023 16:31:24 +0700
Subject: [PATCH 11/12] move jcenter to mavenCentral
---
android/build.gradle | 2 +-
example/android/build.gradle | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/android/build.gradle b/android/build.gradle
index 7c9b74b..2bd66b1 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -5,7 +5,7 @@ buildscript {
ext.kotlin_version = '1.5.20'
repositories {
google()
- jcenter()
+ mavenCentral()
}
dependencies {
diff --git a/example/android/build.gradle b/example/android/build.gradle
index c140bc5..d25dad6 100644
--- a/example/android/build.gradle
+++ b/example/android/build.gradle
@@ -2,7 +2,7 @@ buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
- jcenter()
+ mavenCentral()
}
dependencies {
@@ -14,7 +14,7 @@ buildscript {
allprojects {
repositories {
google()
- jcenter()
+ mavenCentral()
}
}
From ea41be1332e4d587f82a5e967567b3d940200b52 Mon Sep 17 00:00:00 2001
From: Ravindran A
Date: Thu, 14 Dec 2023 18:59:24 +0530
Subject: [PATCH 12/12] Updated
---
README.md | 20 +++
android/build.gradle | 12 +-
android/gradle.properties | 1 -
.../gradle/wrapper/gradle-wrapper.properties | 2 +-
.../presentation_displays/DisplayJson.kt | 2 +-
.../PresentationDisplaysPlugin.kt | 97 +++++++--------
example/android/app/build.gradle | 10 +-
.../android/app/src/debug/AndroidManifest.xml | 3 +-
.../android/app/src/main/AndroidManifest.xml | 3 +-
.../app/src/profile/AndroidManifest.xml | 3 +-
example/android/build.gradle | 6 +-
example/android/gradle.properties | 1 -
.../gradle/wrapper/gradle-wrapper.properties | 2 +-
example/ios/Flutter/AppFrameworkInfo.plist | 2 +-
example/ios/Podfile | 2 +-
example/ios/Podfile.lock | 6 +-
example/ios/Runner.xcodeproj/project.pbxproj | 13 +-
.../xcshareddata/xcschemes/Runner.xcscheme | 2 +-
example/ios/Runner/Info.plist | 4 +
example/lib/main.dart | 32 ++++-
example/pubspec.lock | 115 +++++++++++-------
example/pubspec.yaml | 6 +-
lib/display.dart | 11 +-
lib/displays_manager.dart | 44 +++----
lib/secondary_display.dart | 2 +-
pubspec.lock | 115 ++++++++++--------
pubspec.yaml | 6 +-
27 files changed, 305 insertions(+), 217 deletions(-)
diff --git a/README.md b/README.md
index 40f52ae..9b6728c 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,26 @@ Widget build (BuildContext context) {
);
}
```
+- wesetup new entry point for secondary display so we can decided what we need to call for initialization. Works only for android for now
+```dart
+@pragma('vm:entry-point')
+void secondaryDisplayMain() {
+ /// do something that don't break plugin registration here.
+}
+```
+- Able to package android release build. Works fine in example app.
+
+- Tested example app in android tab and ios tab and things work as expected. Ensure the devices have USB C 3.0 and above else HDMI out is not supported.
+
+- In case of iOS, please refer to example app app delegate. There are few lines of code which needs to be added to your app's app delegate as well for this to work fine in iOS.
+
+- Updated optional issues and null checks
+
+- Added option to hide second display from the first
+
+- WIP support second main in iOS for extended display
+
+- WIP Send data back from 2nd to 1st display
You can take a look at our example to learn more about how the plugin works
diff --git a/android/build.gradle b/android/build.gradle
index 2bd66b1..8fc687f 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -2,14 +2,14 @@ group 'com.namit.presentation_displays'
version '1.0-SNAPSHOT'
buildscript {
- ext.kotlin_version = '1.5.20'
+ ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.1.3'
+ classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
@@ -17,6 +17,7 @@ buildscript {
rootProject.allprojects {
repositories {
google()
+ mavenCentral()
}
}
@@ -24,13 +25,13 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
- compileSdkVersion 31
+ compileSdkVersion 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
- minSdkVersion 19
+ minSdkVersion 21
}
lintOptions {
disable 'InvalidPackage'
@@ -39,5 +40,6 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
- implementation 'com.google.code.gson:gson:2.8.6'
+ implementation 'com.google.code.gson:gson:2.10.1'
+ implementation 'com.android.support:support-annotations:28.0.0'
}
diff --git a/android/gradle.properties b/android/gradle.properties
index 38c8d45..94adc3a 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
-android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
index 3c9d085..3c472b9 100644
--- a/android/gradle/wrapper/gradle-wrapper.properties
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
diff --git a/android/src/main/kotlin/com/namit/presentation_displays/DisplayJson.kt b/android/src/main/kotlin/com/namit/presentation_displays/DisplayJson.kt
index a93232b..3b51244 100644
--- a/android/src/main/kotlin/com/namit/presentation_displays/DisplayJson.kt
+++ b/android/src/main/kotlin/com/namit/presentation_displays/DisplayJson.kt
@@ -13,4 +13,4 @@ data class DisplayJson(
val rotation: Int,
@SerializedName("name")
val name: String
-)
+)
\ No newline at end of file
diff --git a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
index 9b1d9e2..757ce05 100644
--- a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
+++ b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt
@@ -9,6 +9,7 @@ import android.util.Log
import android.view.Display
import androidx.annotation.NonNull
import com.google.gson.Gson
+import io.flutter.FlutterInjector
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor
@@ -24,30 +25,32 @@ import org.json.JSONObject
/** PresentationDisplaysPlugin */
class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.MethodCallHandler {
- private lateinit var channel : MethodChannel
- private lateinit var eventChannel : EventChannel
+ private lateinit var channel: MethodChannel
+ private lateinit var eventChannel: EventChannel
private var flutterEngineChannel: MethodChannel? = null
- private var context:Context?=null
- private var presentation:PresentationDisplay?=null
+ private var context: Context? = null
+ private var presentation: PresentationDisplay? = null
- override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
+ override fun onAttachedToEngine(
+ @NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding
+ ) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, viewTypeId)
channel.setMethodCallHandler(this)
eventChannel = EventChannel(flutterPluginBinding.binaryMessenger, viewTypeEventsId)
- displayManager = flutterPluginBinding.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ displayManager =
+ flutterPluginBinding.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as
+ DisplayManager
val displayConnectedStreamHandler = DisplayConnectedStreamHandler(displayManager)
eventChannel.setStreamHandler(displayConnectedStreamHandler)
}
- companion object{
- private const val viewTypeId = "presentation_displays_plugin"
- private const val viewTypeEventsId = "presentation_displays_plugin_events"
- private var displayManager: DisplayManager? = null
+ companion object {
+ private const val viewTypeId = "presentation_displays_plugin"
+ private const val viewTypeEventsId = "presentation_displays_plugin_events"
+ private var displayManager: DisplayManager? = null
- /**
- * @hide
- */
+ /** @hide */
@Suppress("unused", "DEPRECATION")
@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
@@ -55,7 +58,8 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
channel.setMethodCallHandler(PresentationDisplaysPlugin())
val eventChannel = EventChannel(registrar.messenger(), viewTypeEventsId)
- displayManager = registrar.activity()!!.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ displayManager =
+ registrar.activity()!!.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val displayConnectedStreamHandler = DisplayConnectedStreamHandler(displayManager)
eventChannel.setStreamHandler(displayConnectedStreamHandler)
}
@@ -73,8 +77,8 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
try {
val obj = JSONObject(call.arguments as String)
Log.i(
- TAG,
- "Channel: method: ${call.method} | displayId: ${obj.getInt("displayId")} | routerName: ${
+ TAG,
+ "Channel: method: ${call.method} | displayId: ${obj.getInt("displayId")} | routerName: ${
obj.getString("routerName")
}"
)
@@ -84,16 +88,15 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
if (display != null) {
val flutterEngine = createFlutterEngine(tag)
flutterEngine?.let {
- flutterEngineChannel = MethodChannel(
- it.dartExecutor.binaryMessenger,
- "${viewTypeId}_engine"
- )
- presentation =
- context?.let { it1 -> PresentationDisplay(it1, tag, display) }
+ flutterEngineChannel =
+ MethodChannel(it.dartExecutor.binaryMessenger, "${viewTypeId}_engine")
+ presentation = context?.let { it1 -> PresentationDisplay(it1, tag, display) }
Log.i(TAG, "presentation: $presentation")
presentation?.show()
+
result.success(true)
- } ?: result.error("404", "Can't find FlutterEngine", null)
+ }
+ ?: result.error("404", "Can't find FlutterEngine", null)
} else {
result.error("404", "Can't find display with displayId is $displayId", null)
}
@@ -120,12 +123,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
if (displays != null) {
for (display: Display in displays) {
Log.i(TAG, "display: $display")
- val d = DisplayJson(
- display.displayId,
- display.flags,
- display.rotation,
- display.name
- )
+ val d = DisplayJson(display.displayId, display.flags, display.rotation, display.name)
listJson.add(d)
}
}
@@ -143,14 +141,14 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
}
private fun createFlutterEngine(tag: String): FlutterEngine? {
- if (context == null)
- return null
+ if (context == null) return null
if (FlutterEngineCache.getInstance().get(tag) == null) {
val flutterEngine = FlutterEngine(context!!)
flutterEngine.navigationChannel.setInitialRoute(tag)
- flutterEngine.dartExecutor.executeDartEntrypoint(
- DartExecutor.DartEntrypoint.createDefault()
- )
+ FlutterInjector.instance().flutterLoader().startInitialization(context!!)
+ val path = FlutterInjector.instance().flutterLoader().findAppBundlePath()
+ val entrypoint = DartExecutor.DartEntrypoint(path, "secondaryDisplayMain")
+ flutterEngine.dartExecutor.executeDartEntrypoint(entrypoint)
flutterEngine.lifecycleChannel.appIsResumed()
// Cache the FlutterEngine to be used by FlutterActivity.
FlutterEngineCache.getInstance().put(tag, flutterEngine)
@@ -158,36 +156,35 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M
return FlutterEngineCache.getInstance().get(tag)
}
- override fun onDetachedFromActivity() {
- }
+ override fun onDetachedFromActivity() {}
- override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
- }
+ override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {}
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.context = binding.activity
displayManager = context?.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
}
- override fun onDetachedFromActivityForConfigChanges() {
- }
+ override fun onDetachedFromActivityForConfigChanges() {}
}
-class DisplayConnectedStreamHandler(private var displayManager: DisplayManager?) : EventChannel.StreamHandler {
+class DisplayConnectedStreamHandler(private var displayManager: DisplayManager?) :
+ EventChannel.StreamHandler {
private var sink: EventChannel.EventSink? = null
private var handler: Handler? = null
- private val displayListener = object : DisplayManager.DisplayListener {
- override fun onDisplayAdded(displayId: Int) {
- sink?.success(1)
- }
+ private val displayListener =
+ object : DisplayManager.DisplayListener {
+ override fun onDisplayAdded(displayId: Int) {
+ sink?.success(1)
+ }
- override fun onDisplayRemoved(displayId: Int) {
- sink?.success(0)
- }
+ override fun onDisplayRemoved(displayId: Int) {
+ sink?.success(0)
+ }
- override fun onDisplayChanged(p0: Int) {}
- }
+ override fun onDisplayChanged(p0: Int) {}
+ }
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
sink = events
diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle
index 7f498e1..8873008 100644
--- a/example/android/app/build.gradle
+++ b/example/android/app/build.gradle
@@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
- throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
+ throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
- compileSdkVersion 31
+ compileSdkVersion 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
@@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.namit.presentation_displays_example"
- minSdkVersion 19
+ minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
@@ -52,6 +52,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
+ namespace 'com.namit.presentation_displays_example'
+ lint {
+ disable 'InvalidPackage'
+ }
}
flutter {
diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml
index 4b69847..f880684 100644
--- a/example/android/app/src/debug/AndroidManifest.xml
+++ b/example/android/app/src/debug/AndroidManifest.xml
@@ -1,5 +1,4 @@
-
+
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index ff0c8d0..28838e6 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -1,5 +1,4 @@
-
+
diff --git a/example/android/build.gradle b/example/android/build.gradle
index d25dad6..6f393b6 100644
--- a/example/android/build.gradle
+++ b/example/android/build.gradle
@@ -1,12 +1,12 @@
buildscript {
- ext.kotlin_version = '1.6.10'
+ ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.0'
+ classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
@@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}
-task clean(type: Delete) {
+tasks.register("clean", Delete) {
delete rootProject.buildDir
}
diff --git a/example/android/gradle.properties b/example/android/gradle.properties
index 38c8d45..94adc3a 100644
--- a/example/android/gradle.properties
+++ b/example/android/gradle.properties
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
-android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties
index 752ce5b..6b66533 100644
--- a/example/android/gradle/wrapper/gradle-wrapper.properties
+++ b/example/android/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist
index f2872cf..4f8d4d2 100644
--- a/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/example/ios/Flutter/AppFrameworkInfo.plist
@@ -21,6 +21,6 @@
CFBundleVersion
1.0
MinimumOSVersion
- 9.0
+ 11.0
diff --git a/example/ios/Podfile b/example/ios/Podfile
index 1e8c3c9..88359b2 100644
--- a/example/ios/Podfile
+++ b/example/ios/Podfile
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
-# platform :ios, '9.0'
+# platform :ios, '11.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
index 32d0913..a8ae179 100644
--- a/example/ios/Podfile.lock
+++ b/example/ios/Podfile.lock
@@ -14,9 +14,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/presentation_displays/ios"
SPEC CHECKSUMS:
- Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
+ Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
presentation_displays: 02a9b05f708afe31d23564988f285b4d8019ddcd
-PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
+PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
-COCOAPODS: 1.11.2
+COCOAPODS: 1.14.3
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index 47c8ee1..685a1f1 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 50;
+ objectVersion = 54;
objects = {
/* Begin PBXBuildFile section */
@@ -164,7 +164,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 1300;
+ LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
@@ -230,10 +230,12 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
+ alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
+ "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
@@ -244,6 +246,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
+ alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
@@ -348,7 +351,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -433,7 +436,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -482,7 +485,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
index 3db53b6..b52b2e6 100644
--- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
+++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
@@ -1,6 +1,6 @@
UIViewControllerBasedStatusBarAppearance
+ CADisableMinimumFrameDurationOnPhone
+
+ UIApplicationSupportsIndirectInputEvents
+
diff --git a/example/lib/main.dart b/example/lib/main.dart
index 5eb6102..3a55e24 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -19,9 +19,28 @@ Route generateRoute(RouteSettings settings) {
}
void main() {
+ debugPrint('first main');
runApp(const MyApp());
}
+@pragma('vm:entry-point')
+void secondaryDisplayMain() {
+ debugPrint('second main');
+ runApp(const MySecondApp());
+}
+
+class MySecondApp extends StatelessWidget {
+ const MySecondApp({Key? key}) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return const MaterialApp(
+ onGenerateRoute: generateRoute,
+ initialRoute: 'presentation',
+ );
+ }
+}
+
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@@ -79,9 +98,11 @@ class _DisplayManagerScreenState extends State {
@override
void initState() {
- displayManager.connectedDisplaysChangedStream.listen((event) {
- debugPrint("connected displays changed: $event");
- },);
+ displayManager.connectedDisplaysChangedStream?.listen(
+ (event) {
+ debugPrint("connected displays changed: $event");
+ },
+ );
super.initState();
}
@@ -197,8 +218,7 @@ class _DisplayManagerScreenState extends State {
if (displayId != null) {
for (final display in displays) {
if (display?.displayId == displayId) {
- displayManager.hideSecondaryDisplay(
- displayId: displayId);
+ displayManager.hideSecondaryDisplay(displayId: displayId);
}
}
}
@@ -321,7 +341,7 @@ class _SecondaryScreenState extends State {
Widget build(BuildContext context) {
return Scaffold(
body: SecondaryDisplay(
- callback: (argument) {
+ callback: (dynamic argument) {
setState(() {
value = argument;
});
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 2a930ad..59595ef 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -5,58 +5,58 @@ packages:
dependency: transitive
description:
name: async
- url: "https://pub.dartlang.org"
+ sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
+ url: "https://pub.dev"
source: hosted
- version: "2.8.2"
+ version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- url: "https://pub.dartlang.org"
+ sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
- url: "https://pub.dartlang.org"
+ sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.1"
+ version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
- url: "https://pub.dartlang.org"
+ sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
- url: "https://pub.dartlang.org"
+ sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
+ url: "https://pub.dev"
source: hosted
- version: "1.16.0"
+ version: "1.18.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
- url: "https://pub.dartlang.org"
+ sha256: "1989d917fbe8e6b39806207df5a3fdd3d816cbd090fac2ce26fb45e9a71476e5"
+ url: "https://pub.dev"
source: hosted
version: "1.0.4"
fake_async:
dependency: transitive
description:
name: fake_async
- url: "https://pub.dartlang.org"
+ sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
+ url: "https://pub.dev"
source: hosted
- version: "1.3.0"
+ version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@@ -66,7 +66,8 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
- url: "https://pub.dartlang.org"
+ sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
+ url: "https://pub.dev"
source: hosted
version: "1.0.4"
flutter_test:
@@ -78,44 +79,49 @@ packages:
dependency: transitive
description:
name: lints
- url: "https://pub.dartlang.org"
+ sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
+ url: "https://pub.dev"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
- url: "https://pub.dartlang.org"
+ sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
+ url: "https://pub.dev"
source: hosted
- version: "0.12.11"
+ version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
- url: "https://pub.dartlang.org"
+ sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
+ url: "https://pub.dev"
source: hosted
- version: "0.1.4"
+ version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
- url: "https://pub.dartlang.org"
+ sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
+ url: "https://pub.dev"
source: hosted
- version: "1.7.0"
+ version: "1.10.0"
path:
dependency: transitive
description:
name: path
- url: "https://pub.dartlang.org"
+ sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
+ url: "https://pub.dev"
source: hosted
- version: "1.8.1"
+ version: "1.8.3"
presentation_displays:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
- version: "0.2.3"
+ version: "0.2.4"
sky_engine:
dependency: transitive
description: flutter
@@ -125,51 +131,66 @@ packages:
dependency: transitive
description:
name: source_span
- url: "https://pub.dartlang.org"
+ sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
+ url: "https://pub.dev"
source: hosted
- version: "1.8.2"
+ version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
- url: "https://pub.dartlang.org"
+ sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
+ url: "https://pub.dev"
source: hosted
- version: "1.10.0"
+ version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
- url: "https://pub.dartlang.org"
+ sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.2"
string_scanner:
dependency: transitive
description:
name: string_scanner
- url: "https://pub.dartlang.org"
+ sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
- url: "https://pub.dartlang.org"
+ sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
- url: "https://pub.dartlang.org"
+ sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
+ url: "https://pub.dev"
source: hosted
- version: "0.4.9"
+ version: "0.6.1"
vector_math:
dependency: transitive
description:
name: vector_math
- url: "https://pub.dartlang.org"
+ sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.2"
+ version: "2.1.4"
+ web:
+ dependency: transitive
+ description:
+ name: web
+ sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.3.0"
sdks:
- dart: ">=2.17.0-0 <3.0.0"
- flutter: ">=2.10.3"
+ dart: ">=3.2.0-194.0.dev <4.0.0"
+ flutter: ">=3.10.0"
diff --git a/example/pubspec.yaml b/example/pubspec.yaml
index 0f6459e..6bec10d 100644
--- a/example/pubspec.yaml
+++ b/example/pubspec.yaml
@@ -3,14 +3,14 @@ description: Demonstrates how to use the presentation_displays plugin.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
-publish_to: 'none' # Remove this line if you wish to publish to pub.dev
+publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
- sdk: ">=2.12.0 <3.0.0"
+ sdk: ">=3.0.0 <4.0.0"
# Flutter versions prior to 1.12 did not support the
# flutter.plugin.platforms map.
- flutter: ">=2.10.3"
+ flutter: ">=3.10.0"
dependencies:
flutter:
diff --git a/lib/display.dart b/lib/display.dart
index 9834a4c..12b9a10 100644
--- a/lib/display.dart
+++ b/lib/display.dart
@@ -4,6 +4,13 @@ Display displayFromJson(Map json) => Display(
name: json['name'],
rotation: json['rotation']);
+/// for release please check response from invokeMethod
+Display displayReleaseFromJson(Map json) => Display(
+ displayId: json['a'],
+ flag: json['b'],
+ name: json['d'],
+ rotation: json['c']);
+
/// The default Display id, which is the id of the built-in primary display
/// assuming there is one.
const int DEFAULT_DISPLAY = 0;
@@ -110,7 +117,7 @@ class Display {
/// Each logical display has a unique id.
/// The default display has id [DEFAULT_DISPLAY]
///
- int displayId = DEFAULT_DISPLAY;
+ int? displayId = DEFAULT_DISPLAY;
/// Returns a combination of flags that describe the capabilities of the display.
/// @return The display flags.
@@ -138,7 +145,7 @@ class Display {
///
///
/// @return The display's name.
- String name;
+ String? name;
Display(
{required this.displayId, this.flag, required this.name, this.rotation});
diff --git a/lib/displays_manager.dart b/lib/displays_manager.dart
index abe961a..113a108 100644
--- a/lib/displays_manager.dart
+++ b/lib/displays_manager.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
+import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:presentation_displays/display.dart';
@@ -22,7 +23,7 @@ const _transferDataToPresentation = "transferDataToPresentation";
/// Use the following methods to query the real display area:
/// [DisplayManager.getDisplays], [DisplayManager.getNameByDisplayId],
/// [DisplayManager.getNameByIndex], [DisplayManager.showSecondaryDisplay],
-/// [DisplayManager.transferDataToPresentation]
+/// [DisplayManager.transferDataToPresentation], [DisplayManager.hideSecondaryDisplay]
///
///
/// [DisplayManager.getDisplays]
@@ -34,8 +35,9 @@ const String DISPLAY_CATEGORY_PRESENTATION =
class DisplayManager {
final _displayMethodChannelId = "presentation_displays_plugin";
final _displayEventChannelId = "presentation_displays_plugin_events";
- late MethodChannel _displayMethodChannel;
- late EventChannel _displayEventChannel;
+
+ late MethodChannel? _displayMethodChannel;
+ late EventChannel? _displayEventChannel;
DisplayManager() {
_displayMethodChannel = MethodChannel(_displayMethodChannelId);
@@ -56,14 +58,16 @@ class DisplayManager {
/// @return An array containing all displays sorted by order of preference.
///
/// See [DISPLAY_CATEGORY_PRESENTATION]
- FutureOr?> getDisplays({String? category}) async {
- List origins = await jsonDecode(await _displayMethodChannel
- .invokeMethod(_listDisplay, category)) ??
+ Future?> getDisplays({String? category}) async {
+ List origins = await jsonDecode((await _displayMethodChannel
+ ?.invokeMethod(_listDisplay, category))) ??
[];
List displays = [];
for (var element in origins) {
final map = jsonDecode(jsonEncode(element));
- displays.add(displayFromJson(map));
+ displays.add(kReleaseMode
+ ? displayReleaseFromJson(map as Map)
+ : displayFromJson(map as Map));
}
return displays;
}
@@ -77,8 +81,7 @@ class DisplayManager {
///
/// @return The display's name.
/// May be null.
- FutureOr getNameByDisplayId(int displayId,
- {String? category}) async {
+ Future getNameByDisplayId(int displayId, {String? category}) async {
List displays = await getDisplays(category: category) ?? [];
String? name;
@@ -97,7 +100,7 @@ class DisplayManager {
///
/// @return The display's name
/// May be null.
- FutureOr getNameByIndex(int index, {String? category}) async {
+ Future getNameByIndex(int index, {String? category}) async {
List displays = await getDisplays(category: category) ?? [];
String? name;
if (index >= 0 && index <= displays.length) name = displays[index].name;
@@ -114,8 +117,8 @@ class DisplayManager {
///
/// return [Future] about the status has been display or not
Future? showSecondaryDisplay(
- {required int displayId, required String routerName}) {
- return _displayMethodChannel.invokeMethod(
+ {required int displayId, required String routerName}) async {
+ return await _displayMethodChannel?.invokeMethod(
_showPresentation,
"{"
"\"displayId\": $displayId,"
@@ -129,13 +132,12 @@ class DisplayManager {
///
///
/// return [Future] about the status has been display or not
- Future? hideSecondaryDisplay(
- {required int displayId}) {
- return _displayMethodChannel.invokeMethod(
+ Future? hideSecondaryDisplay({required int displayId}) async {
+ return await _displayMethodChannel?.invokeMethod(
_hidePresentation,
"{"
- "\"displayId\": $displayId"
- "}");
+ "\"displayId\": $displayId"
+ "}");
}
/// Transfer data to a secondary display
@@ -190,14 +192,14 @@ class DisplayManager {
///
///
/// return [Future] the value to determine whether or not the data has been transferred successfully
- Future? transferDataToPresentation(dynamic arguments) {
- return _displayMethodChannel.invokeMethod(
+ Future? transferDataToPresentation(dynamic arguments) async {
+ return await _displayMethodChannel?.invokeMethod(
_transferDataToPresentation, arguments);
}
/// Subscribe to the stream to get notifications about connected / disconnected displays
/// Streams [1] for new connected display and [0] for disconnected display
- Stream get connectedDisplaysChangedStream {
- return _displayEventChannel.receiveBroadcastStream().cast();
+ Stream? get connectedDisplaysChangedStream {
+ return _displayEventChannel?.receiveBroadcastStream().cast();
}
}
diff --git a/lib/secondary_display.dart b/lib/secondary_display.dart
index 2b5bd73..522f414 100644
--- a/lib/secondary_display.dart
+++ b/lib/secondary_display.dart
@@ -26,7 +26,7 @@ class SecondaryDisplay extends StatefulWidget {
class _SecondaryDisplayState extends State {
final _presentationChannel = "presentation_displays_plugin_engine";
- MethodChannel? _presentationMethodChannel;
+ late MethodChannel? _presentationMethodChannel;
@override
void initState() {
diff --git a/pubspec.lock b/pubspec.lock
index a8dba89..6df145f 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -5,51 +5,50 @@ packages:
dependency: transitive
description:
name: async
- url: "https://pub.dartlang.org"
+ sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
+ url: "https://pub.dev"
source: hosted
- version: "2.8.2"
+ version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- url: "https://pub.dartlang.org"
+ sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
+ sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
+ url: "https://pub.dev"
source: hosted
- version: "1.3.1"
+ version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
- url: "https://pub.dartlang.org"
+ sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
- url: "https://pub.dartlang.org"
+ sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
+ url: "https://pub.dev"
source: hosted
- version: "1.15.0"
+ version: "1.18.0"
fake_async:
dependency: transitive
description:
name: fake_async
- url: "https://pub.dartlang.org"
+ sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@@ -59,7 +58,8 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
- url: "https://pub.dartlang.org"
+ sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
+ url: "https://pub.dev"
source: hosted
version: "1.0.4"
flutter_test:
@@ -71,37 +71,42 @@ packages:
dependency: transitive
description:
name: lints
- url: "https://pub.dartlang.org"
+ sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
+ url: "https://pub.dev"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
- url: "https://pub.dartlang.org"
+ sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
+ url: "https://pub.dev"
source: hosted
- version: "0.12.11"
+ version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
- url: "https://pub.dartlang.org"
+ sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
+ url: "https://pub.dev"
source: hosted
- version: "0.1.3"
+ version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
- url: "https://pub.dartlang.org"
+ sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
+ url: "https://pub.dev"
source: hosted
- version: "1.7.0"
+ version: "1.10.0"
path:
dependency: transitive
description:
name: path
- url: "https://pub.dartlang.org"
+ sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
+ url: "https://pub.dev"
source: hosted
- version: "1.8.0"
+ version: "1.8.3"
sky_engine:
dependency: transitive
description: flutter
@@ -111,58 +116,66 @@ packages:
dependency: transitive
description:
name: source_span
- url: "https://pub.dartlang.org"
+ sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
+ url: "https://pub.dev"
source: hosted
- version: "1.8.1"
+ version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
- url: "https://pub.dartlang.org"
+ sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
+ url: "https://pub.dev"
source: hosted
- version: "1.10.0"
+ version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
- url: "https://pub.dartlang.org"
+ sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.2"
string_scanner:
dependency: transitive
description:
name: string_scanner
- url: "https://pub.dartlang.org"
+ sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
- url: "https://pub.dartlang.org"
+ sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
- url: "https://pub.dartlang.org"
+ sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
+ url: "https://pub.dev"
source: hosted
- version: "0.4.8"
- typed_data:
+ version: "0.6.1"
+ vector_math:
dependency: transitive
description:
- name: typed_data
- url: "https://pub.dartlang.org"
+ name: vector_math
+ sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
+ url: "https://pub.dev"
source: hosted
- version: "1.3.0"
- vector_math:
+ version: "2.1.4"
+ web:
dependency: transitive
description:
- name: vector_math
- url: "https://pub.dartlang.org"
+ name: web
+ sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
+ url: "https://pub.dev"
source: hosted
- version: "2.1.1"
+ version: "0.3.0"
sdks:
- dart: ">=2.14.0 <3.0.0"
- flutter: ">=2.10.3"
+ dart: ">=3.2.0-194.0.dev <4.0.0"
+ flutter: ">=3.10.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index e51f61b..8a0a1da 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,13 +1,13 @@
name: presentation_displays
description: Flutter plugin supports to run on two screens. It's basically a tablet connected to another screen via an HDMI or Wireless
homepage: https://github.com/VNAPNIC/presentation-displays
-version: 0.2.3
+version: 0.2.4
environment:
- sdk: ">=2.12.0 <3.0.0"
+ sdk: ">=3.0.0 <4.0.0"
# Flutter versions prior to 1.12 did not support the
# flutter.plugin.platforms map.
- flutter: ">=2.10.3"
+ flutter: ">=3.10.0"
dependencies:
flutter: