fluttercommunity / fluttercommunity/flutter_webview_plugin

OnUrlChange/onStateChange STOP tracking when moving from one webview to another webview instance in same app

オープン
#543 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Java
スター
1.5k
フォーク
938
PR マージ指標
30日以内にマージされた PR はありません

説明

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);
}
});
}
});
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、サンプルの initState と dispose のライフサイクルから始め、特に onUrlChanged と onStateChanged のサブスクリプション、および flutterWebViewPlugin.close()/dispose() の呼び出しを確認します。1 枚のカードを開き、その webview を離れてから別のカードを開くという報告された手順を再現し、その後、plugin のネイティブな webview ライフサイクル処理を追跡します。両方の stream が webview インスタンスをまたいでナビゲーションと状態変更を引き続き報告すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
dart, java
領域
mobile-dev
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。