Skip to content

Escape keystroke doesn't work #132138

@koral--

Description

@koral--

Is there an existing issue for this?

Steps to reproduce

  1. Navigate forward to another route using Navigator.push.
  2. Press Escape button (use adb shell input keyevent ESCAPE if 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.2

Screenshots 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.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: routesNavigator, Router, and related APIs.found in release: 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions