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

Get Android Back Button event #37726

Open
feinstein opened this issue Aug 6, 2019 · 4 comments
Open

Get Android Back Button event #37726

feinstein opened this issue Aug 6, 2019 · 4 comments
Labels
c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@feinstein
Copy link
Contributor

In my application I want to disable the back button, but I want the user to be able to pop the current screen if he click the AppBar back button.

Basically I have a form inside a PageView, so at each new form field, the PageView moves forward, the back button is supposed to go back one step and not pop the entire form from the screen. But still, if the user wants to pop out, he can using the back button at the top.

Currently we can only do it using WillPopScope, but this isn't enough, as WillPopScope doesn't differentiate between a physical Back button press or an AppBar's back button press.

@ja2375
Copy link

ja2375 commented Aug 7, 2019

You can always handle the back button event yourself:

AppBar(
    leading: IconButton(
        icon: Icon(Icons.arrow_back),
        onPressed: () => Navigator.of(context).pop(),
    ), 
    title: Text("Sample"),
)

@feinstein
Copy link
Contributor Author

That handles the AppBar back button, not the physical Android Back button.

Thats exactly what I did in my code, I handle the AppBar in one part and WillPopScope in another, but that's not convenient, you are not handling Android's Back button directly, you are solving the problem assembling other solutions together and I think Flutter could do better and simpler.

@ja2375
Copy link

ja2375 commented Aug 7, 2019

In fact this could be implemented in Flutter, but i think this is not convenient as Flutter not only supports Android but many other platforms. And Android is the only platform having a dedicated back button, so implementing this would not make much sense. Handling the AppBar's back event and using WillPopScope makes more sense when compiling for all platforms, not just Android.
If Flutter provided a way to control Android's back button events, you would need to write extra code to support every other platform.

That's my personal opinion.

@feinstein
Copy link
Contributor Author

Flutter sometimes have properties that only make sense on Android or iOS, like with TextInputAction.

The Android Back button could be implemented in a generic way, the same way we can could get a mouse button press event, it could be a form of system button, or something like it.

@BondarenkoStas BondarenkoStas added the c: new feature Nothing broken; request for a new capability label Sep 19, 2019
@VladyslavBondarenko VladyslavBondarenko added framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically labels Jan 16, 2020
@goderbauer goderbauer added the P6 label Jan 24, 2023
@flutter-triage-bot flutter-triage-bot bot added P3 Issues that are less important to the Flutter project and removed P6 labels Jun 28, 2023
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-android Owned by Android platform team triaged-android Triaged by Android platform team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests

6 participants