fluttercommunity / fluttercommunity/flutter_webview_plugin

onUrlChanged always listen even I cancel the subscription & dispose the webview

Open
#809 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.5k
Forks
938
PR merge metrics
No merged PRs in 30d

Description

I noticed that whenever I click the webview for the 2nd time . onUrlChanged listen ( duplicate ) the same data .

[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.2 19C57,
locale en-MY)
• Flutter version 1.17.5 at /Users/Users/flutter
• Framework revision 8af6b2f038 (7 weeks ago), 2020-06-30
12:53:55 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[✓] Android toolchain - develop for Android devices (Android SDK
version 30.0.1)
• Android SDK at /Users/Users/Library/Android/sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.8.4

[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android
Studio.app/Contents
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.48.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.13.2

`final flutterWebViewPlugin = FlutterWebviewPlugin();
StreamSubscription _onUrlChanged;

@override
void initState() {
super.initState();
flutterWebViewPlugin.close();
_onUrlChanged = flutterWebViewPlugin.onUrlChanged.listen((url) {
if (mounted) {
if (url.contains(
'${EnviromentConfig.baseUrl}/?status_id=1')) {
Uri uri = Uri.parse(url);
_redirect(uri);
} else if (url.contains(
'${EnviromentConfig.baseUrl}/?status_id=0')) {
Uri uri = Uri.parse(url);
String message = uri.queryParameters['message'].replaceAll('_', ' ');
Navigator.pop(_scaffoldKey.currentContext);
final snackBar =
SnackBar(backgroundColor: Colors.red, content: Text(message));
_scaffoldKey.currentState.showSnackBar(snackBar);
}
}
});
}

@override
void dispose() {
_onUrlChanged.cancel();
flutterWebViewPlugin.dispose();
super.dispose();
}`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the onUrlChanged subscription and the dispose lifecycle shown in the report, then reproduce the second webview interaction using the supplied example. Trace whether cancellation and webview disposal stop callbacks; done means a later webview interaction does not deliver duplicate URL-change events.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.