Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss presentation display from second screen #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class _DisplayManagerScreenState extends State<DisplayManagerScreen> {
children: <Widget>[
_getDisplays(),
_showPresentation(),
_dismissPresentation(),
_transferData(),
_getDisplayeById(),
_getDisplayByIndex(),
Expand Down Expand Up @@ -166,6 +167,21 @@ class _DisplayManagerScreenState extends State<DisplayManagerScreen> {
);
}

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,
Expand Down
6 changes: 6 additions & 0 deletions lib/displays_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// <p>
Expand Down Expand Up @@ -175,4 +176,9 @@ class DisplayManager {
return _displayMethodChannel?.invokeMethod<bool?>(
_transferDataToPresentation, arguments);
}

/// Dismiss the presentation display
Future<bool?>? dismissPresentation() async {
return await _displayMethodChannel?.invokeMethod<bool?>(_dismiss);
}
}