Repository navigation
Escape keystroke doesn't work #132138
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Navigate forward to another route using
Navigator.push. - Press Escape button (use
adb shell input keyevent ESCAPEif hardware keyboard is not available)
Expected results
Escape keystrokes works like a back button in native Android - causes back navigation like a system back button.
Actual results
Escape keystrokes are ignored apart from DialogRoute.
Code sample
Complete project: https://github.com/koral--/escape_demo
Code sample
main.dart:
import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
const FirstRoute({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Route'),
),
body: Center(
child: Column(
children: [
ElevatedButton(
child: const Text('Open material page route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SecondRoute()),
);
},
),
ElevatedButton(
child: const Text('Open dialog route'),
onPressed: () {
Navigator.push(
context,
DialogRoute(
context: context,
builder: (context) => const SecondRoute()),
);
},
),
ElevatedButton(
child: const Text('Open second Activity'),
onPressed: () {
const AndroidIntent(action: 'second_activity').launch();
},
),
],
),
),
);
}
}
class SecondRoute extends StatelessWidget {
const SecondRoute({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Route'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Go back!'),
),
),
);
}
}
To be added to AndroidManifest.xml inside <application> node:
<activity android:name=".SecondActivity" android:exported="false">
<intent-filter>
<action android:name="second_activity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>android/app/src/main/kotlin/com/example/escape_demo/SecondActivity.kt file:
package com.example.escape_demo
import android.app.Activity
import android.os.Bundle
import android.widget.TextView
class SecondActivity : Activity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(TextView(this).apply {
text = "Second Activity"
})
}
}Dependency to be added:
android_intent_plus: ^4.0.2Screenshots or Video
Screenshots / Video demonstration
Screen.Recording.2023-08-08.at.18.19.01.mov
Logs
Logs
V/IntentSender( 8234): Sending intent Intent { act=second_activity (has extras) }
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-x64, locale en-US)
• Flutter version 3.10.6 on channel stable at /usr/local/Caskroom/flutter/3.0.5/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f468f3366c (4 weeks ago), 2023-07-12 15:19:05 -0700
• Engine revision cdbeda788a
• Dart version 3.0.6
• DevTools version 2.23.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/koral/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/koral/Library/Android/sdk
• Java binary at: /usr/bin/java
• Java version OpenJDK Runtime Environment Corretto-17.0.4.8.1 (build 17.0.4+8-LTS)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E300c
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio
• Android Studio at /Applications/Android Studio Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] VS Code
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (3 available)
(stripped)
[✓] Network resources
• All expected network resources are available.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Type
Projects
- StatusShow more project fieldsDone (PR merged)
Activity
darshankawar commentedon Aug 9, 2023
Thanks for the detailed report. Seeing the same behavior as reported.
stable, master flutter doctor -v
johnmccutchan commentedon Aug 16, 2023
This appears to be a Framework issue- MaterialPageRoute hard codes "barrierDismissible" as false. As the original report indicates "DialogRoute"
8 remaining items
[-][Android]Escape keystroke doesn't work[/-][+]Escape keystroke doesn't work[/+]bleroux commentedon Aug 28, 2023
Escape key support for
ModalRoutewas added in #59310.#70156 introduced a change to deactivate the escape key shortcut when
barrierDismissibleis false.To get the escape key feature on
MaterialPageRouteone solution would be to setbarrierDismissibleto true (for the moment it is always false, seeflutter/packages/flutter/lib/src/widgets/pages.dart
Line 42 in 7c13003
But it seems to be overkill because:
ModalBarrierfor everyMaterialPageRoute@gspencergoog I'm not sure what the best solution would be, do you have some insight?
gspencergoog commentedon Aug 28, 2023
It seems that PageRoute has always returned false for
barrierDismissable, presumably because if it covers the whole screen, there's no way to dismiss it by tapping/clicking outside of it. However, for this case, it makes sense to be able to set it to true. I'm not sure what effect that would have on theModalRoutebase class: it might cause it to add aModalBarrierit wouldn't have otherwise, but probably not.So, I'd suggest we change
PageRouteto allowbarrierDismissableto be set to true, add constructor parameters to it and toMaterialPageRoute(and probably any other subclasses), and document that for full-page routes it only means that the escape key binding is enabled.Expose barrierDismissible in PageRoute constructor (#133659)
github-actions commentedon Sep 13, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Expose barrierDismissible in PageRoute constructor (#133659)