-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/plugins
#6996Closed
Copy link
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
When pop any route include Webview. Webview's instance has been never been disposed.
Still running can be accessed on Safari development tools.
Steps to Reproduce
- Execute
flutter runon the code sample - Press the + button two times to open two new routes with webview
- Press the back button two times to pop
- Check on safari development tools
Expected results: Just on 1 webview's instance show up on safari development tools
Actual results: 3 webview's instances show up on safari development tools
Flutter: 3.3.10
Dart: 2.18.6
webview_flutter: 4.0.1
webview_flutter_android: 3.1.1
webview_flutter_wkwebview: 3.0.1
Xcode 14.2
iPhone 11
iOS 16.2
Checked on webview_flutter 3.0.4 issue still occurs
Code sample
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: "home",
onGenerateRoute: _onGenerateRoute,
);
}
Route? _onGenerateRoute(RouteSettings settings) {
Widget screen = const SizedBox();
switch (settings.name ?? "") {
case "home":
screen = const MyHomePage();
break;
}
return MaterialPageRoute(builder: (_) => screen, settings: settings);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late final WebViewController _controller;
@override
void initState() {
super.initState();
late final PlatformWebViewControllerCreationParams params;
if (WebViewPlatform.instance is WebKitWebViewPlatform) {
params = WebKitWebViewControllerCreationParams(
allowsInlineMediaPlayback: true,
mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
);
} else {
params = const PlatformWebViewControllerCreationParams();
}
_controller = WebViewController.fromPlatformCreationParams(params)
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..loadRequest(Uri.parse('https://flutter.dev'));
if (_controller.platform is AndroidWebViewController) {
AndroidWebViewController.enableDebugging(true);
(_controller.platform as AndroidWebViewController)
.setMediaPlaybackRequiresUserGesture(false);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Home"),
),
body: WebViewWidget(controller: _controller),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).pushNamed("home");
},
tooltip: 'New',
child: const Icon(Icons.add),
),
);
}
}
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
