Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9c0e7cc

Browse files
committed
WIP A platform channel API to declare that the nav stack is empty
1 parent e8a5130 commit 9c0e7cc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
136136
result.error("error", exception.getMessage(), null);
137137
}
138138
break;
139+
case "SystemNavigator.isEmpty":
140+
platformMessageHandler.navigatorIsEmpty();
141+
result.success(null);
142+
break;
139143
case "SystemNavigator.pop":
140144
platformMessageHandler.popSystemNavigator();
141145
result.success(null);
@@ -509,6 +513,8 @@ public interface PlatformMessageHandler {
509513
*/
510514
void setSystemUiOverlayStyle(@NonNull SystemChromeStyle systemUiOverlayStyle);
511515

516+
void navigatorIsEmpty();
517+
512518
/**
513519
* The Flutter application would like to pop the top item off of the Android app's navigation
514520
* back stack.

shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public void setSystemUiOverlayStyle(
109109
setSystemChromeSystemUIOverlayStyle(systemUiOverlayStyle);
110110
}
111111

112+
@Override
113+
public void navigatorIsEmpty() {
114+
PlatformPlugin.this.navigatorIsEmpty();
115+
}
116+
112117
@Override
113118
public void popSystemNavigator() {
114119
PlatformPlugin.this.popSystemNavigator();
@@ -475,18 +480,28 @@ private void setSystemChromeSystemUIOverlayStyle(
475480
currentTheme = systemChromeStyle;
476481
}
477482

483+
private void navigatorIsEmpty() {
484+
Log.e("justin", "navigatorIsEmpty in PlatformPlugin");
485+
// TODO(justinmc): Can't quite call it like this, need FlutterActivity.
486+
// activity.unregisterOnBackInvokedCallback();
487+
}
488+
478489
private void popSystemNavigator() {
479490
if (platformPluginDelegate != null && platformPluginDelegate.popSystemNavigator()) {
480491
// A custom behavior was executed by the delegate. Don't execute default behavior.
481492
return;
482493
}
483494

484495
// TODO(justinmc): This is another use of backpresseddispatcher that is not
485-
// blocking the pback gesture for me.
496+
// blocking the pback gesture for me. It seems like this if is false, so the
497+
// app exits here.
486498
if (activity instanceof OnBackPressedDispatcherOwner) {
487499
Log.e("justin", "calling onBackPressed in popSystemNavigator in PlatformPlugin");
488500
((OnBackPressedDispatcherOwner) activity).getOnBackPressedDispatcher().onBackPressed();
489501
} else {
502+
Log.e(
503+
"justin",
504+
"popSystemNavigator in PlatformPlugin finishing the activity because it's not an OnBackPressedDispatcherOwner");
490505
activity.finish();
491506
}
492507
}

0 commit comments

Comments
 (0)