-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
App Crashes after clicking on dropdown (Using inappwebview) #182
Comments
You can try the latest version of the plugin! Also, this plugin changed its name to |
I tried it with the latest version & correct name - same issue, but different stacktrace:
This seems to be a known issue with other webview implementations (see also: flutter/flutter#25767) - do you think a fix or workaround for this library is possible? |
@Poplipo Thanks for the link! Maybe, a possible workaround could be done using javascript handlers to communicate with the web page:
However, I need to check it more as soon as possible, because I'm fixing also other issues! |
@Poplipo Ok, I found a possible fix for that using JavaScript, so javascript must be enabled, otherwise it won't work. I will post it as soon as possible! |
…temporary workaround for html dropdowns (issue #182)
@Poplipo I have added the new To test my latest commit with the workaround, you can point the dependency on the master branch of this repository (see https://flutter.dev/docs/development/packages-and-plugins/using-packages#dependencies-on-unpublished-packages). You need to enable it like this: ...
child: InAppWebView(
initialUrl: "https://myUrl.com",
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions(
debuggingEnabled: true,
),
androidInAppWebViewOptions: AndroidInAppWebViewOptions(
dropDownWorkaroudEnabled: true
)
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
... Let me know if now the dropdowns work! Thanks! |
@pichillilorenzo Thanks for the update, just tried on the emulator and still crashes for me. This is how I used it. Do I still need to do something to make it work? I will try on an actual device as soon as I get free, Thank you.
|
@vshashi01 can you share the URL that gives you the problem? Also, I need to test another workaround that could be better then this one! I will update it as soon as possible |
Thanks for the workaround! I tried it, but it looks like it doesn't trigger the change event on the select-tag when you select an option in the native dialog. We meanwhile looked at an alternative workaround too, based on comments in the issue linked earlier - we change the constructor and pass an ActivityContext to the webview instead of the application context. (view reply below for formatted code) This seems to work well on smartphone in our case, but we are running into some issues on tablet, since dropdowns are handled differently on tablet (they don't create a native dialog it seems). We are looking into this and will update as well! |
|
Update: With the above If we use the If we use the latest tag Just to make sure, I tried a native android app with a standard webkit webview - in this case, dropdowns are handled correctly on both smartphone and tablet. Hope this helps! |
@Poplipo Using the I need to try another workaround (using JavaScript) I have in mind that should work for both Android phones and tablets. It could break some css styles coming from external resources (not inline css styles) for I will let you know as soon as possible. |
@Poplipo @vshashi01 I have updated the repository! Try with the latest commit. Now it should work and call also the |
@pichillilorenzo It now works on an actual device on the first launch. The current problem seems to be after the first click, reclicking on the dropdown again, crashes the app instead. This is still better than previously I think but if it could be fixed, that should be good. Also, it still crashes on emulator, but that could be a weird emulator problem. |
@vshashi01 can you post some html (with css and javascript) code or url you are sure is not working with, please?? Otherwise I can't test and fix it. I tested on a very simple html containing two |
As stated here flutter/flutter#25767 (comment), a temporary workaround would be using an external Javascript lib such as Select2. |
@DieBrise yeah, I have seen that, but my workaround tries to mimic the same behavior as android webview would do, wrapping the original |
The full code for this example: import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: InAppWebViewPage()
);
}
}
class InAppWebViewPage extends StatefulWidget {
@override
_InAppWebViewPageState createState() => new _InAppWebViewPageState();
}
class _InAppWebViewPageState extends State<InAppWebViewPage> with WidgetsBindingObserver {
InAppWebViewController webView;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("InAppWebView")
),
body: SafeArea(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialData: InAppWebViewInitialData(
data: """
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Flutter InAppWebView</title>
</head>
<body>
<select style="height: 30px;">
<option value="option-1">Option 1</option>
<option value="option-2">Option 2</option>
<option value="option-3">Option 3</option>
<option value="option-4">Option 4</option>
</select>
<br>
<br>
<select multiple="multiple" style="height: 30px; min-width: 250px;">
<option value="option-1">Option 1</option>
<option value="option-2">Option 2</option>
<option value="option-3">Option 3</option>
<option value="option-4">Option 4</option>
</select>
</body>
</html>
"""
),
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions(
debuggingEnabled: true,
),
androidInAppWebViewOptions: AndroidInAppWebViewOptions(
dropDownWorkaroundEnabled: true
)
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) {
},
),
)
),
]))
);
}
} |
@pichillilorenzo Using your example above with the InitialData works fine. However, I took out the select2 lib from my webpage and tried it again, the app still crashes. Both on my real phone and Android emulator. I thought it may have to do with something on my webpage, so I changed the URL to W3School's Select page. Same result. |
@DieBrise can you post the URL of your webpage, so I can debug my workaround? |
@DieBrise @Poplipo @vshashi01 Updated with the latest commit! Try the latest commit! Now it should work also on Also, this workaround is applied as soon as the web page fires the
So, if a user clicks on a select element before this event, then it will crash because the workaround needs to wait for this JavaScript event, otherwise, it won't work. Full code example using the W3School's Select page: import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: InAppWebViewPage()
);
}
}
class InAppWebViewPage extends StatefulWidget {
@override
_InAppWebViewPageState createState() => new _InAppWebViewPageState();
}
class _InAppWebViewPageState extends State<InAppWebViewPage> with WidgetsBindingObserver {
InAppWebViewController webView;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("InAppWebView")
),
body: SafeArea(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select",
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions(
debuggingEnabled: true,
),
androidInAppWebViewOptions: AndroidInAppWebViewOptions(
dropDownWorkaroundEnabled: true
)
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) {
},
),
)
),
]))
);
}
} Result: |
@pichillilorenzo It's a private URL, is there any way I can send it to you? |
@pichillilorenzo I just tried your latest update, on the website I am trying to use it on, it works fine to click it twice now. However, if I focused on a text input and then focused back to the dropdown menu, then it crashed again. Since its a confidential site, I thought i would make an example with w3S school to simulate the issue, but on my device even then basic select tag through w3S crashes as shown in the gif below. Could this be a device issue? |
I have the same issue, app crashes when i tap on the dropdown You can try with this html |
@davedega @Poplipo @DieBrise @vshashi01 I have finally found a fix that works without using any javascript code! Now it should always work. Please try my latest commit and let me know! Thanks to everyone |
@pichillilorenzo great job! |
@pichillilorenzo thanks so much for your hard work on this! Because of deadlines, we ended up implementing a native activity, but we'll keep this lib in mind for our next project :) |
@pichillilorenzo it works just as expected. Will you be making an official release with the current changes, or should I continue to depend on the git repo? |
@vshashi01 yes, I'm going to release a new major release (3.0.0) as soon as possibile with a lot of fixes, new methods, events and options! I think I can publish it today or tomorrow |
hi, |
@ridz0n3 because that option has been deleted. If you are using the master branch of this plugin, then it shuold work without any option, instead, if you are using the latest published version 2.1.0+1, then this fix isn't there. You need to wait for the official release (version 3.0.0). |
@pichillilorenzo I can still reproduce this crash with Flutter 1.12 release and the master branch of this repo. I can reproduce this crash both in the emulator and on a Samsung device. |
Hi when you are releasing the new version |
|
@ShanmugavelGK it's not maintained anymore apparently, we are maintaining a fork of this package flutter_polywebview, feel free to try it, just change the package name, all the rest remain the same |
@arnaudelub Thanks for updating bro. |
This error happened again in flutter 3.3.4, I'm using android 5.1 on a physical device (Moto G). The Error in Stacktrace/Logcat is exactly that. When I was using Flutter version 2.10.5 this error did not happen. |
Is there any workaround? still facing this issue in |
@AbdulWahabKhanDanat create a new issue with all the related info, such as Android version, flutter version, code example with reproducible steps, etc. |
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 and a minimal reproduction of the issue. |
Environment
Android version: Android 6.0
Device information: Emulator (Pixel 3a XL API 23)
Description
Expected behavior:
Should open the dropdown
Current behavior:
App Crashes
Steps to reproduce
Stacktrace/Logcat
--------- beginning of crash
11-01 22:35:30.694 2978-2978/com.vuka.vuka_app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.vuka.vuka_app, PID: 2978
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1351)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2774)
at android.content.res.Resources.getLayout(Resources.java:1165)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:369)
at org.chromium.content.browser.input.SelectPopupAdapter.getView(SelectPopupAdapter.java:56)
at android.widget.AbsListView.obtainView(AbsListView.java:2346)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1280)
at android.widget.ListView.onMeasure(ListView.java:1188)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18788)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1191)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Flutter doctor log
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.15 19A603, locale en-GB)
• Flutter version 1.9.1+hotfix.2 at /Users/sayanporya/Flutter/flutter
• Framework revision 2d2a1ffec9 (8 weeks ago), 2019-09-06 18:39:49 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/sayanporya/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 28.0.3
• ANDROID_HOME = /Users/sayanporya/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
pod setup
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] IntelliJ IDEA Community Edition (version 2019.1.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 38.2.2
• Dart plugin version 191.8369
[✓] VS Code (version 1.38.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.4.1
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 6.0 (API 23) (emulator)
The text was updated successfully, but these errors were encountered: