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

[Android] Back button doesn't go back a page but quits webview #37

Closed
amuttsch opened this issue Feb 12, 2018 · 7 comments
Closed

[Android] Back button doesn't go back a page but quits webview #37

amuttsch opened this issue Feb 12, 2018 · 7 comments

Comments

@amuttsch
Copy link

On Android when navigating through websites I want to use the back button to go back a page. This is currently not possible, the webview will be closed. Is this intentional?

I use the example from the repository and can reproduce this behavior with the fullscreen and widget webview. I digged in the source code and it should be able to set the back button to go back in the webviews history first by setting a setOnKeyListener on the webview (see here).

How is the behaviour on iOS? If I recall correctly, you swipe from left to right to go back a page in Safari. Is this currently possible?

For the Android part I can create a pull request to change the back button behaviour. Should it be configurable or always go back until we reach the end of the history before exiting the webview?

@lejard-h
Copy link
Collaborator

I need to check the behavior on iOS, but yes it is a bug on Android.

I don't have much time to work on it, but I can review PR.

@amuttsch
Copy link
Author

Thanks for your quick response, I can try to fix it. Can you give me a hint how to compile flutter_webview? I'm new to flutter + dart and when I try flutter run or flutter build apk inside the examples folder, I get the following error message:

Initializing gradle...                                0,8s
Resolving dependencies...
* Error running Gradle:
Exit code 1 from: C:\Code\flutter_webview_plugin\example\android\gradlew.bat app:properties:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Code\flutter_webview_plugin\example\android\build.gradle' line: 20

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not resolve all dependencies for configuration ':app:_debugApk'.
      > A problem occurred configuring project ':flutter_webview_plugin'.
         > Failed to notify project evaluation listener.
            > com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Please review your Gradle project setup in the android/ folder.

I couldn't figue out if I have to compile the plugin itself before, but a flutter build apk in the root directory doesn't work either, because the flutter library isn't included as a dependency in the android project.

@amuttsch
Copy link
Author

amuttsch commented Feb 12, 2018

Got it working, it seems like gradle 4 doesn't work, I changed it to 3.3 and it works now. See flutter/flutter#10236

@zoechi
Copy link

zoechi commented Mar 20, 2018

The back arrow in the app bar still closes the WebView for me.
Anything I might have missed.
I use add a widget that hasnew WebviewScaffold(...) in build() using the router.

@amuttsch
Copy link
Author

This is the correct behaviour imho @zoechi. The back arrow in the action bar indicates a back to the previous screen / activity, not a page back. For such a functionality you could add a button in the action bar (page back / forward), but I think you'd have to add the methods calls to the native webviews for that in a PR.

@zoechi
Copy link

zoechi commented Mar 20, 2018

@amuttsch thanks for clarification.
So this PR is about the Android back button, not the one in the AppBar?

@amuttsch
Copy link
Author

@zoechi Correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants