From db3eb7662b389817a71f5052c723cdfc2e0fca55 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 15 Jul 2025 18:25:18 +0530 Subject: [PATCH 1/2] Fix to avoid lastEnableArguments to be set to null due to cancelOnLeavePiP call --- lib/src/floating.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/floating.dart b/lib/src/floating.dart index 736c516..dbef529 100644 --- a/lib/src/floating.dart +++ b/lib/src/floating.dart @@ -117,7 +117,6 @@ class Floating { /// /// Note: this will not make any effect on Android SDK older than 26. Future enable(EnableArguments arguments) async { - lastEnableArguments = arguments; final (aspectRatio, sourceRectHint, autoEnable) = switch (arguments) { ImmediatePiP(:final aspectRatio, :final sourceRectHint) => ( aspectRatio, @@ -139,6 +138,11 @@ class Floating { // current ones, e.g. current one is ImmediatePiP but OnLeavePiP // was called before. await cancelOnLeavePiP(); + + // Moved this here as setting it on the first line does not make sense since + // it will be overridden by the cancelOnLeavePiP call. + lastEnableArguments = arguments; + final bool? enabledSuccessfully = await _channel.invokeMethod( 'enablePip', { From e2194d2ed811abf4d7e5717188f243a893589a6b Mon Sep 17 00:00:00 2001 From: dev-aman Date: Wed, 16 Jul 2025 12:31:51 +0530 Subject: [PATCH 2/2] Update exception handling for cancelOnLeavePiP Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/src/floating.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/floating.dart b/lib/src/floating.dart index dbef529..2fdd922 100644 --- a/lib/src/floating.dart +++ b/lib/src/floating.dart @@ -137,12 +137,12 @@ class Floating { // Cancel any previous settings in case it would interfere with the // current ones, e.g. current one is ImmediatePiP but OnLeavePiP // was called before. - await cancelOnLeavePiP(); - - // Moved this here as setting it on the first line does not make sense since - // it will be overridden by the cancelOnLeavePiP call. - lastEnableArguments = arguments; - + try { + await cancelOnLeavePiP(); + } finally { + // Ensure lastEnableArguments is always set, even if cancelOnLeavePiP throws. + lastEnableArguments = arguments; + } final bool? enabledSuccessfully = await _channel.invokeMethod( 'enablePip', {