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

Is there idea FlutterView(Android) intercept the 'back' keydown? #4867

Closed
tain335 opened this issue Jul 10, 2016 · 6 comments
Closed

Is there idea FlutterView(Android) intercept the 'back' keydown? #4867

tain335 opened this issue Jul 10, 2016 · 6 comments

Comments

@tain335
Copy link

tain335 commented Jul 10, 2016

No description provided.

@abarth
Copy link
Contributor

abarth commented Jul 10, 2016

You'll want to add something like this to your activity:

    @Override
    public void onBackPressed() {
        if (flutterView != null) {
            flutterView.popRoute();
            return;
        }
        super.onBackPressed();
    }

@tain335
Copy link
Author

tain335 commented Jul 11, 2016

But if FlutterView has no any route can pop, and the app should exit(in my usecase), is there a way to check the route can pop?

@abarth
Copy link
Contributor

abarth commented Jul 11, 2016

If you try to pop a route and the view doesn't have a route that it can pop, it will end the current activity:

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/binding.dart#L166

@tain335
Copy link
Author

tain335 commented Jul 11, 2016

OH, it is clear in my case.And if I want to do other thing(not pop a route) just make a toast or make a dialog in FlutterView, how can do it?

@Hixie Hixie modified the milestone: Flutter 1.0 Sep 12, 2016
@Hixie
Copy link
Contributor

Hixie commented Jan 31, 2017

You can add a WidgetsBindingObserver that listens to didPopRoute, and returns true.

@Hixie Hixie closed this as completed Jan 31, 2017
@github-actions
Copy link

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 -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants