fluttercommunity / fluttercommunity/flutter_webview_plugin
OnUrlChange/onStateChange STOP tracking when moving from one webview to another webview instance in same app
- Lenguaje dominante
- Java
- Estrellas
- 1.5k
- Forks
- 938
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I Love this Plugin. I got everything I needed but one little issue. It may be a quick fix for you :)
I saw this issue description from @l-k22 in [issue](https://github.com/fluttercommunity/flutter_webview_plugin/issues/30#issuecomment-437330743) and thought it was well worded for my case(already developed but stuck) with some changes **in bold** as below
I can get the scaffold to work with a bottom navigation bar when it is returned directly in my build method. However, I have made some alterations to my app so I now have a
**listview of cards which each lead to a different website**. When the user clicks on card it opens the webview and I wrote an onUrlChange so that if a website brings them to an unsupported url_Scheme (like market:// or intent://) it will bring them out to URL launcher-like plugin.
Observation: It works when the first card is chosen and an unsupported link is clicked like to go to AppStore and play store
Issue: when a user goes out of webview card select and goes to another card (or even comes back to the same card) it doesn't work. Upon looking at the console, onUrlChange/OnStateChange both stop functioning when leaving webview :(
```
StreamSubscription _onDestroy;
StreamSubscription _onUrlChanged;
StreamSubscription _onHttpError;
StreamSubscription _onStateChanged;
@override
void dispose() {
_onUrlChanged.cancel();
_onHttpError.cancel();
_onDestroy.cancel();
_onStateChanged.cancel();
flutterWebViewPlugin.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
flutterWebViewPlugin.close();
// Add a listener to on destroy WebView, so you can make came actions.
_onDestroy = flutterWebViewPlugin.onDestroy.listen((_) {
print("destroy");
});
_onStateChanged =
flutterWebViewPlugin.onStateChanged.listen((WebViewStateChanged state) {
print("onStateChanged: ${state.type} ${state.url}");
});
_onUrlChanged = flutterWebViewPlugin.onUrlChanged.listen((String url) {
print("OnUrlChange navigating to...$url");
if (mounted) {
setState(() {
if (!(url.startsWith("www") || url.startsWith("https") ||
url.startsWith("http") || !(url.contains("play.google.com")) ||
!(url.contains("apps.apple.com")))) {
FlutterWebBrowser.openWebPage(url: url,
androidToolbarColor: Colors.redAccent);
}
});
}
});
}
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza con el ciclo de vida de ejemplo de initState y dispose, especialmente las suscripciones a onUrlChanged y onStateChanged y las llamadas a flutterWebViewPlugin.close()/dispose(). Reproduce la secuencia indicada: abrir una tarjeta, salir de su webview y abrir otra; después, rastrea la gestión nativa del ciclo de vida de la webview por parte del plugin. Se considera terminado cuando ambos streams siguen informando de la navegación y de los cambios de estado entre distintas instancias de webview.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- dart, java
- Área
- mobile-dev
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 30/100