From effefdb24bda4ec4e8386dfa859a3ff5ccb59062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6n=20=20Boldizs=C3=A1r?= Date: Mon, 11 Dec 2023 12:15:21 +0100 Subject: [PATCH] dismiss presentation display from second screen --- .../PresentationDisplaysPlugin.kt | 13 ++++++++++++- example/lib/main.dart | 16 ++++++++++++++++ lib/displays_manager.dart | 6 ++++++ 3 files changed, 34 insertions(+), 1 deletion(-) 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 150819b..ff7f555 100644 --- a/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt +++ b/android/src/main/kotlin/com/namit/presentation_displays/PresentationDisplaysPlugin.kt @@ -26,6 +26,7 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M private var flutterEngineChannel: MethodChannel? = null private var displayManager: DisplayManager? = null private var context: Context? = null + private var presentation: PresentationDisplay? = null override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { channel = MethodChannel(flutterPluginBinding.flutterEngine.dartExecutor, viewTypeId) @@ -68,7 +69,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() @@ -107,6 +108,16 @@ class PresentationDisplaysPlugin : FlutterPlugin, ActivityAware, MethodChannel.M result.success(false) } } + "dismiss" -> { + if(presentation != null) { + try { + presentation?.dismiss() + result.success(true) + } catch (e: Exception) { + } + } + result.success(false) + } } } diff --git a/example/lib/main.dart b/example/lib/main.dart index 24374eb..2112ba3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -91,6 +91,7 @@ class _DisplayManagerScreenState extends State { children: [ _getDisplays(), _showPresentation(), + _dismissPresentation(), _transferData(), _getDisplayeById(), _getDisplayByIndex(), @@ -166,6 +167,21 @@ class _DisplayManagerScreenState extends State { ); } + Widget _dismissPresentation() { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Button( + title: "Dismiss presentation", + onPressed: () async { + await displayManager.dismissPresentation(); + }), + const Divider(), + ], + ); + } + Widget _transferData() { return Column( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/displays_manager.dart b/lib/displays_manager.dart index 49a12b1..cbf42d8 100644 --- a/lib/displays_manager.dart +++ b/lib/displays_manager.dart @@ -9,6 +9,7 @@ import 'package:presentation_displays/secondary_display.dart'; const _listDisplay = "listDisplay"; const _showPresentation = "showPresentation"; const _transferDataToPresentation = "transferDataToPresentation"; +const _dismiss = "dismiss"; /// Display category: secondary display. ///

@@ -175,4 +176,9 @@ class DisplayManager { return _displayMethodChannel?.invokeMethod( _transferDataToPresentation, arguments); } + + /// Dismiss the presentation display + Future? dismissPresentation() async { + return await _displayMethodChannel?.invokeMethod(_dismiss); + } }