From e8f8ad88e72826a6163d4903df33f9991e1aa44b Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 16 Jul 2020 20:33:20 -0700 Subject: [PATCH 01/14] Add surface view --- packages/webview_flutter/CHANGELOG.md | 16 ++++++ .../android/app/src/main/AndroidManifest.xml | 4 ++ .../webview_flutter/example/lib/main.dart | 1 + .../lib/src/webview_android.dart | 50 +++++++++++++++++++ .../webview_flutter/lib/webview_flutter.dart | 27 ++++++++-- packages/webview_flutter/pubspec.yaml | 2 +- 6 files changed, 95 insertions(+), 5 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 04155a509b80..3cc0eaf64523 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,3 +1,19 @@ +## 0.3.23 + +* Add `Webview.useExperimentalAndroidSurfaceView` flag that builds Android WebView using hybrid views. + To use this feature, set this value to `true` and have the following lines in your `android/app/src/main/AndroidManifest.xml`: +```xml + +. +. + +. +. + +``` + ## 0.3.22+1 * Update the `setAndGetScrollPosition` to use hard coded values and add a `pumpAndSettle` call. diff --git a/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml b/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml index f895f92bd7a4..52d6029f297d 100644 --- a/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml +++ b/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml @@ -13,6 +13,10 @@ + + { print('Page finished loading: $url'); }, gestureNavigationEnabled: true, + useExperimentalAndroidSurfaceView: true, ); }), floatingActionButton: favoriteButton(), diff --git a/packages/webview_flutter/lib/src/webview_android.dart b/packages/webview_flutter/lib/src/webview_android.dart index f7afcc0637a3..4c4543590489 100644 --- a/packages/webview_flutter/lib/src/webview_android.dart +++ b/packages/webview_flutter/lib/src/webview_android.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -58,6 +59,55 @@ class AndroidWebView implements WebViewPlatform { ); } + // ignore: public_member_api_docs + Widget buildWithSurfaceView({ + BuildContext context, + CreationParams creationParams, + @required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler, + WebViewPlatformCreatedCallback onWebViewPlatformCreated, + Set> gestureRecognizers, + }) { + assert(webViewPlatformCallbacksHandler != null); + return PlatformViewLink( + viewType: 'plugins.flutter.io/webview', + surfaceFactory: ( + BuildContext context, + PlatformViewController controller, + ) { + return AndroidViewSurface( + controller: controller, + gestureRecognizers: gestureRecognizers ?? + const >{}, + hitTestBehavior: PlatformViewHitTestBehavior.opaque, + ); + }, + onCreatePlatformView: (PlatformViewCreationParams params) { + return PlatformViewsService.initSurfaceAndroidView( + id: params.id, + viewType: 'plugins.flutter.io/webview', + // WebView content is not affected by the Android view's layout direction, + // we explicitly set it here so that the widget doesn't require an ambient + // directionality. + layoutDirection: TextDirection.rtl, + creationParams: MethodChannelWebViewPlatform.creationParamsToMap( + creationParams, + ), + creationParamsCodec: const StandardMessageCodec(), + ) + ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) + ..addOnPlatformViewCreatedListener((int id) { + if (onWebViewPlatformCreated == null) { + return; + } + onWebViewPlatformCreated( + MethodChannelWebViewPlatform(id, webViewPlatformCallbacksHandler), + ); + }) + ..create(); + }, + ); + } + @override Future clearCookies() => MethodChannelWebViewPlatform.clearCookies(); } diff --git a/packages/webview_flutter/lib/webview_flutter.dart b/packages/webview_flutter/lib/webview_flutter.dart index 2635b0446fa2..dedbff916a0a 100644 --- a/packages/webview_flutter/lib/webview_flutter.dart +++ b/packages/webview_flutter/lib/webview_flutter.dart @@ -156,6 +156,7 @@ class WebView extends StatefulWidget { this.userAgent, this.initialMediaPlaybackPolicy = AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, + this.useExperimentalAndroidSurfaceView = false, }) : assert(javascriptMode != null), assert(initialMediaPlaybackPolicy != null), super(key: key); @@ -329,6 +330,16 @@ class WebView extends StatefulWidget { /// The default policy is [AutoMediaPlaybackPolicy.require_user_action_for_all_media_types]. final AutoMediaPlaybackPolicy initialMediaPlaybackPolicy; + /// Whether to use `AndroidViewSurface` and `SurfaceAndroidViewController` to create the widget. + /// + /// This flag is temporary and is highly subject to removal. One should only + /// use this if they are willing to test [WebView] features that aren't + /// available in the standard version and acknowledges that it is possible + /// this can have slower performance and/or unpredictable bugs. + /// + /// Defaults to false. + final bool useExperimentalAndroidSurfaceView; + @override State createState() => _WebViewState(); } @@ -341,7 +352,17 @@ class _WebViewState extends State { @override Widget build(BuildContext context) { - return WebView.platform.build( + final WebViewPlatform platform = WebView.platform; + if (widget.useExperimentalAndroidSurfaceView && platform is AndroidWebView) { + return platform.buildWithSurfaceView( + context: context, + onWebViewPlatformCreated: _onWebViewPlatformCreated, + webViewPlatformCallbacksHandler: _platformCallbacksHandler, + gestureRecognizers: widget.gestureRecognizers, + creationParams: _creationParamsfromWidget(widget), + ); + } + return platform.build( context: context, onWebViewPlatformCreated: _onWebViewPlatformCreated, webViewPlatformCallbacksHandler: _platformCallbacksHandler, @@ -445,9 +466,7 @@ WebSettings _clearUnchangedWebSettings( Set _extractChannelNames(Set channels) { final Set channelNames = channels == null - // TODO(iskakaushik): Remove this when collection literals makes it to stable. - // ignore: prefer_collection_literals - ? Set() + ? {} : channels.map((JavascriptChannel channel) => channel.name).toSet(); return channelNames; } diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 2ccc3efcccef..8a4a62ea76a6 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 0.3.22+1 +version: 0.3.23 homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter environment: From 6a5927de27233ee51ee4acaaa07ee8d8d0bd4b84 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 16 Jul 2020 20:37:49 -0700 Subject: [PATCH 02/14] Add test for scrolling hybrid view --- .../test_driver/webview_flutter_e2e.dart | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart index 3468067de603..7661dd2515bf 100644 --- a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart +++ b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart @@ -608,6 +608,77 @@ void main() { }); }); + group('Programmatic Scroll with hybrid view', () { + testWidgets('setAndGetScrollPosition', (WidgetTester tester) async { + final String scrollTestPage = ''' + + + + + + +
+ + + '''; + + final String scrollTestPageBase64 = + base64Encode(const Utf8Encoder().convert(scrollTestPage)); + + final Completer pageLoaded = Completer(); + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WebView( + initialUrl: + 'data:text/html;charset=utf-8;base64,$scrollTestPageBase64', + onWebViewCreated: (WebViewController controller) { + controllerCompleter.complete(controller); + }, + onPageFinished: (String url) { + pageLoaded.complete(null); + }, + useExperimentalAndroidSurfaceView: true, + ), + ), + ); + + final WebViewController controller = await controllerCompleter.future; + await pageLoaded.future; + + await tester.pumpAndSettle(Duration(seconds: 3)); + + // Check scrollTo() + const int X_SCROLL = 123; + const int Y_SCROLL = 321; + + await controller.scrollTo(X_SCROLL, Y_SCROLL); + int scrollPosX = await controller.getScrollX(); + int scrollPosY = await controller.getScrollY(); + expect(X_SCROLL, scrollPosX); + expect(Y_SCROLL, scrollPosY); + + // Check scrollBy() (on top of scrollTo()) + await controller.scrollBy(X_SCROLL, Y_SCROLL); + scrollPosX = await controller.getScrollX(); + scrollPosY = await controller.getScrollY(); + expect(X_SCROLL * 2, scrollPosX); + expect(Y_SCROLL * 2, scrollPosY); + }); + }); + group('NavigationDelegate', () { final String blankPage = ""; final String blankPageEncoded = 'data:text/html;charset=utf-8;base64,' + From 8e90cc3a50febe07f761972859d28c3d6d3881f0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Sun, 19 Jul 2020 19:00:41 -0700 Subject: [PATCH 03/14] Create a custom platform for android surface view --- .../webview_flutter/example/lib/main.dart | 7 +- .../test_driver/webview_flutter_e2e.dart | 4 +- .../lib/src/webview_android.dart | 49 ------------ .../webview_flutter/lib/webview_flutter.dart | 80 ++++++++++++++----- 4 files changed, 67 insertions(+), 73 deletions(-) diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index 841f7a0ff5a4..42c437d00dc1 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -35,6 +35,12 @@ class _WebViewExampleState extends State { final Completer _controller = Completer(); + @override + void initState() { + super.initState(); + WebView.platform = SurfaceAndroidWebView(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -75,7 +81,6 @@ class _WebViewExampleState extends State { print('Page finished loading: $url'); }, gestureNavigationEnabled: true, - useExperimentalAndroidSurfaceView: true, ); }), floatingActionButton: favoriteButton(), diff --git a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart index 7661dd2515bf..bd38ca0c577a 100644 --- a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart +++ b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart @@ -609,6 +609,7 @@ void main() { }); group('Programmatic Scroll with hybrid view', () { + WebView.platform = SurfaceAndroidWebView(); testWidgets('setAndGetScrollPosition', (WidgetTester tester) async { final String scrollTestPage = ''' @@ -650,7 +651,6 @@ void main() { onPageFinished: (String url) { pageLoaded.complete(null); }, - useExperimentalAndroidSurfaceView: true, ), ), ); @@ -676,6 +676,8 @@ void main() { scrollPosY = await controller.getScrollY(); expect(X_SCROLL * 2, scrollPosX); expect(Y_SCROLL * 2, scrollPosY); + + WebView.platform = null; }); }); diff --git a/packages/webview_flutter/lib/src/webview_android.dart b/packages/webview_flutter/lib/src/webview_android.dart index 4c4543590489..059073932395 100644 --- a/packages/webview_flutter/lib/src/webview_android.dart +++ b/packages/webview_flutter/lib/src/webview_android.dart @@ -59,55 +59,6 @@ class AndroidWebView implements WebViewPlatform { ); } - // ignore: public_member_api_docs - Widget buildWithSurfaceView({ - BuildContext context, - CreationParams creationParams, - @required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler, - WebViewPlatformCreatedCallback onWebViewPlatformCreated, - Set> gestureRecognizers, - }) { - assert(webViewPlatformCallbacksHandler != null); - return PlatformViewLink( - viewType: 'plugins.flutter.io/webview', - surfaceFactory: ( - BuildContext context, - PlatformViewController controller, - ) { - return AndroidViewSurface( - controller: controller, - gestureRecognizers: gestureRecognizers ?? - const >{}, - hitTestBehavior: PlatformViewHitTestBehavior.opaque, - ); - }, - onCreatePlatformView: (PlatformViewCreationParams params) { - return PlatformViewsService.initSurfaceAndroidView( - id: params.id, - viewType: 'plugins.flutter.io/webview', - // WebView content is not affected by the Android view's layout direction, - // we explicitly set it here so that the widget doesn't require an ambient - // directionality. - layoutDirection: TextDirection.rtl, - creationParams: MethodChannelWebViewPlatform.creationParamsToMap( - creationParams, - ), - creationParamsCodec: const StandardMessageCodec(), - ) - ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) - ..addOnPlatformViewCreatedListener((int id) { - if (onWebViewPlatformCreated == null) { - return; - } - onWebViewPlatformCreated( - MethodChannelWebViewPlatform(id, webViewPlatformCallbacksHandler), - ); - }) - ..create(); - }, - ); - } - @override Future clearCookies() => MethodChannelWebViewPlatform.clearCookies(); } diff --git a/packages/webview_flutter/lib/webview_flutter.dart b/packages/webview_flutter/lib/webview_flutter.dart index dedbff916a0a..1a5f8055eb36 100644 --- a/packages/webview_flutter/lib/webview_flutter.dart +++ b/packages/webview_flutter/lib/webview_flutter.dart @@ -6,11 +6,14 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'platform_interface.dart'; import 'src/webview_android.dart'; import 'src/webview_cupertino.dart'; +import 'src/webview_method_channel.dart'; /// Optional callback invoked when a web view is first created. [controller] is /// the [WebViewController] for the created web view. @@ -64,6 +67,60 @@ enum NavigationDecision { navigate, } +/// Android [WebViewPlatform] that uses [AndroidViewSurface] to build the [WebView] widget. +/// +/// To use this, set [WebView.platform] to an instance of this class. +class SurfaceAndroidWebView extends AndroidWebView { + @override + Widget build({ + BuildContext context, + CreationParams creationParams, + WebViewPlatformCreatedCallback onWebViewPlatformCreated, + Set> gestureRecognizers, + @required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler, + }) { + assert(webViewPlatformCallbacksHandler != null); + return PlatformViewLink( + viewType: 'plugins.flutter.io/webview', + surfaceFactory: ( + BuildContext context, + PlatformViewController controller, + ) { + return AndroidViewSurface( + controller: controller, + gestureRecognizers: gestureRecognizers ?? + const >{}, + hitTestBehavior: PlatformViewHitTestBehavior.opaque, + ); + }, + onCreatePlatformView: (PlatformViewCreationParams params) { + return PlatformViewsService.initSurfaceAndroidView( + id: params.id, + viewType: 'plugins.flutter.io/webview', + // WebView content is not affected by the Android view's layout direction, + // we explicitly set it here so that the widget doesn't require an ambient + // directionality. + layoutDirection: TextDirection.rtl, + creationParams: MethodChannelWebViewPlatform.creationParamsToMap( + creationParams, + ), + creationParamsCodec: const StandardMessageCodec(), + ) + ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) + ..addOnPlatformViewCreatedListener((int id) { + if (onWebViewPlatformCreated == null) { + return; + } + onWebViewPlatformCreated( + MethodChannelWebViewPlatform(id, webViewPlatformCallbacksHandler), + ); + }) + ..create(); + }, + ); + } +} + /// Decides how to handle a specific navigation request. /// /// The returned [NavigationDecision] determines how the navigation described by @@ -156,7 +213,6 @@ class WebView extends StatefulWidget { this.userAgent, this.initialMediaPlaybackPolicy = AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, - this.useExperimentalAndroidSurfaceView = false, }) : assert(javascriptMode != null), assert(initialMediaPlaybackPolicy != null), super(key: key); @@ -330,16 +386,6 @@ class WebView extends StatefulWidget { /// The default policy is [AutoMediaPlaybackPolicy.require_user_action_for_all_media_types]. final AutoMediaPlaybackPolicy initialMediaPlaybackPolicy; - /// Whether to use `AndroidViewSurface` and `SurfaceAndroidViewController` to create the widget. - /// - /// This flag is temporary and is highly subject to removal. One should only - /// use this if they are willing to test [WebView] features that aren't - /// available in the standard version and acknowledges that it is possible - /// this can have slower performance and/or unpredictable bugs. - /// - /// Defaults to false. - final bool useExperimentalAndroidSurfaceView; - @override State createState() => _WebViewState(); } @@ -352,17 +398,7 @@ class _WebViewState extends State { @override Widget build(BuildContext context) { - final WebViewPlatform platform = WebView.platform; - if (widget.useExperimentalAndroidSurfaceView && platform is AndroidWebView) { - return platform.buildWithSurfaceView( - context: context, - onWebViewPlatformCreated: _onWebViewPlatformCreated, - webViewPlatformCallbacksHandler: _platformCallbacksHandler, - gestureRecognizers: widget.gestureRecognizers, - creationParams: _creationParamsfromWidget(widget), - ); - } - return platform.build( + return WebView.platform.build( context: context, onWebViewPlatformCreated: _onWebViewPlatformCreated, webViewPlatformCallbacksHandler: _platformCallbacksHandler, From da2a0b98626a96530d1d5d380f2743651a500f38 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 20 Jul 2020 09:00:35 -0700 Subject: [PATCH 04/14] Formatting and changelog --- packages/webview_flutter/CHANGELOG.md | 5 +++-- .../example/test_driver/webview_flutter_e2e.dart | 6 +++--- packages/webview_flutter/lib/webview_flutter.dart | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 3cc0eaf64523..7d434f45e3ad 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,7 +1,8 @@ ## 0.3.23 -* Add `Webview.useExperimentalAndroidSurfaceView` flag that builds Android WebView using hybrid views. - To use this feature, set this value to `true` and have the following lines in your `android/app/src/main/AndroidManifest.xml`: +* Add support for building `WebView` widget with Android hybrid views. To use this feature, set + `WebView.platform` to an instance of `SurfaceAndroidWebView` and add the following lines to your + `android/app/src/main/AndroidManifest.xml`: ```xml . diff --git a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart index bd38ca0c577a..07586a9481c4 100644 --- a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart +++ b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart @@ -633,18 +633,18 @@ void main() { '''; final String scrollTestPageBase64 = - base64Encode(const Utf8Encoder().convert(scrollTestPage)); + base64Encode(const Utf8Encoder().convert(scrollTestPage)); final Completer pageLoaded = Completer(); final Completer controllerCompleter = - Completer(); + Completer(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: WebView( initialUrl: - 'data:text/html;charset=utf-8;base64,$scrollTestPageBase64', + 'data:text/html;charset=utf-8;base64,$scrollTestPageBase64', onWebViewCreated: (WebViewController controller) { controllerCompleter.complete(controller); }, diff --git a/packages/webview_flutter/lib/webview_flutter.dart b/packages/webview_flutter/lib/webview_flutter.dart index 1a5f8055eb36..3fe0d861174e 100644 --- a/packages/webview_flutter/lib/webview_flutter.dart +++ b/packages/webview_flutter/lib/webview_flutter.dart @@ -83,9 +83,9 @@ class SurfaceAndroidWebView extends AndroidWebView { return PlatformViewLink( viewType: 'plugins.flutter.io/webview', surfaceFactory: ( - BuildContext context, - PlatformViewController controller, - ) { + BuildContext context, + PlatformViewController controller, + ) { return AndroidViewSurface( controller: controller, gestureRecognizers: gestureRecognizers ?? From 29d2b88ed88c540479cd5505c1c447d0e14b9ef6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Fri, 18 Sep 2020 10:26:34 -0700 Subject: [PATCH 05/14] test reformat and better documentation --- packages/webview_flutter/CHANGELOG.md | 14 +------------- .../android/app/src/main/AndroidManifest.xml | 4 ---- .../example/test_driver/webview_flutter_e2e.dart | 13 +++++++++---- .../webview_flutter/lib/src/webview_android.dart | 1 - packages/webview_flutter/lib/webview_flutter.dart | 6 ++++++ 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 9480af3c9b3e..514be4d978da 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,19 +1,7 @@ ## 0.3.23 * Add support for building `WebView` widget with Android hybrid views. To use this feature, set - `WebView.platform` to an instance of `SurfaceAndroidWebView` and add the following lines to your - `android/app/src/main/AndroidManifest.xml`: -```xml - -. -. - -. -. - -``` + `WebView.platform` to an instance of `SurfaceAndroidWebView`. ## 0.3.22+2 diff --git a/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml b/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml index 52d6029f297d..f895f92bd7a4 100644 --- a/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml +++ b/packages/webview_flutter/example/android/app/src/main/AndroidManifest.xml @@ -13,10 +13,6 @@ - - @@ -676,8 +683,6 @@ void main() { scrollPosY = await controller.getScrollY(); expect(X_SCROLL * 2, scrollPosX); expect(Y_SCROLL * 2, scrollPosY); - - WebView.platform = null; }); }); diff --git a/packages/webview_flutter/lib/src/webview_android.dart b/packages/webview_flutter/lib/src/webview_android.dart index 059073932395..f7afcc0637a3 100644 --- a/packages/webview_flutter/lib/src/webview_android.dart +++ b/packages/webview_flutter/lib/src/webview_android.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; -import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; diff --git a/packages/webview_flutter/lib/webview_flutter.dart b/packages/webview_flutter/lib/webview_flutter.dart index 3fe0d861174e..c3921e1f18dc 100644 --- a/packages/webview_flutter/lib/webview_flutter.dart +++ b/packages/webview_flutter/lib/webview_flutter.dart @@ -70,6 +70,12 @@ enum NavigationDecision { /// Android [WebViewPlatform] that uses [AndroidViewSurface] to build the [WebView] widget. /// /// To use this, set [WebView.platform] to an instance of this class. +/// +/// This implementation uses Hybrid Composition to render the [WebView] on +/// Android. It solves multiple issues related to accessibility and interacting +/// with the [WebView] at the cost of some performance on Android version below +/// 10. See https://github.com/flutter/flutter/issues/61133 for more +/// information. class SurfaceAndroidWebView extends AndroidWebView { @override Widget build({ From 7c30a7ecbbcad3abe6223feb656b861838165d65 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Fri, 18 Sep 2020 10:32:39 -0700 Subject: [PATCH 06/14] slight doc change --- packages/webview_flutter/lib/webview_flutter.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/lib/webview_flutter.dart b/packages/webview_flutter/lib/webview_flutter.dart index c3921e1f18dc..b15eb330463c 100644 --- a/packages/webview_flutter/lib/webview_flutter.dart +++ b/packages/webview_flutter/lib/webview_flutter.dart @@ -72,8 +72,8 @@ enum NavigationDecision { /// To use this, set [WebView.platform] to an instance of this class. /// /// This implementation uses Hybrid Composition to render the [WebView] on -/// Android. It solves multiple issues related to accessibility and interacting -/// with the [WebView] at the cost of some performance on Android version below +/// Android. It solves multiple issues related to accessibility and interaction +/// with the [WebView] at the cost of some performance on Android versions below /// 10. See https://github.com/flutter/flutter/issues/61133 for more /// information. class SurfaceAndroidWebView extends AndroidWebView { From c82be0a2283dd7392c151351168e4d77267f6fe0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 21 Sep 2020 12:50:19 -0700 Subject: [PATCH 07/14] update docs/changelog and hopefully fix ios --- packages/webview_flutter/CHANGELOG.md | 21 ++++++++++++++++++- .../webview_flutter/example/lib/main.dart | 3 ++- .../webview_flutter/lib/webview_flutter.dart | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 41ee93961a42..2b5bb7e45152 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,7 +1,26 @@ ## 0.3.24 * Add support for building `WebView` widget with Android hybrid views. To use this feature, set - `WebView.platform` to an instance of `SurfaceAndroidWebView`. + `WebView.platform` to an instance of `SurfaceAndroidWebView`. For example: + +```dart +import 'dart:io'; + +class WebViewExample extends StatefulWidget { + @override + void initState() { + super.initState(); + if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); + } + + @override + Widget build(BuildContext context) { + return WebView( + initialUrl: 'https://flutter.dev', + ); + } +} +``` ## 0.3.23 diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index 42c437d00dc1..ff25e8a16c9b 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -38,7 +39,7 @@ class _WebViewExampleState extends State { @override void initState() { super.initState(); - WebView.platform = SurfaceAndroidWebView(); + if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); } @override diff --git a/packages/webview_flutter/lib/webview_flutter.dart b/packages/webview_flutter/lib/webview_flutter.dart index b15eb330463c..5e2bffd6539d 100644 --- a/packages/webview_flutter/lib/webview_flutter.dart +++ b/packages/webview_flutter/lib/webview_flutter.dart @@ -71,10 +71,10 @@ enum NavigationDecision { /// /// To use this, set [WebView.platform] to an instance of this class. /// -/// This implementation uses Hybrid Composition to render the [WebView] on +/// This implementation uses hybrid composition to render the [WebView] on /// Android. It solves multiple issues related to accessibility and interaction /// with the [WebView] at the cost of some performance on Android versions below -/// 10. See https://github.com/flutter/flutter/issues/61133 for more +/// 10. See https://github.com/flutter/flutter/wiki/Hybrid-Composition for more /// information. class SurfaceAndroidWebView extends AndroidWebView { @override From 28faa1a21d9b1ffc8a459775a478eaa3b9199d92 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 21 Sep 2020 12:56:42 -0700 Subject: [PATCH 08/14] fix ios test --- .../example/test_driver/webview_flutter_e2e.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart index a08a54a2554f..2a17c53a4c3f 100644 --- a/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart +++ b/packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart @@ -684,7 +684,7 @@ void main() { expect(X_SCROLL * 2, scrollPosX); expect(Y_SCROLL * 2, scrollPosY); }); - }); + }, skip: !Platform.isAndroid); group('NavigationDelegate', () { final String blankPage = ""; From 0e39be027b40c6e0c273d8e9a8eca6e301ca1520 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 21 Sep 2020 17:41:37 -0700 Subject: [PATCH 09/14] version bump --- packages/webview_flutter/CHANGELOG.md | 2 +- packages/webview_flutter/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 2b5bb7e45152..4ac3ca9149f6 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.3.24 +## 0.4.0 * Add support for building `WebView` widget with Android hybrid views. To use this feature, set `WebView.platform` to an instance of `SurfaceAndroidWebView`. For example: diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 2212ef6c4059..483bd39c1739 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,11 +1,11 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 0.3.24 +version: 0.4.0 homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter environment: sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.12.13+hotfix.5" + flutter: ">=1.22.0" dependencies: flutter: From 5ac33e9ea85dfbe222a54bffd9d30bb0ff492405 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 29 Sep 2020 09:36:23 -0700 Subject: [PATCH 10/14] version bump --- packages/webview_flutter/CHANGELOG.md | 52 ++++++++++++-- packages/webview_flutter/README.md | 67 +++++++++++++------ .../example/ios/Runner/Info.plist | 2 - packages/webview_flutter/pubspec.yaml | 2 +- 4 files changed, 95 insertions(+), 28 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 6de5035fa963..a0161a632907 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,11 +1,47 @@ -## 0.4.0 - -* Add support for building `WebView` widget with Android hybrid views. To use this feature, set - `WebView.platform` to an instance of `SurfaceAndroidWebView`. For example: +## 1.0.0 + +We are happy to announce that the WebView plugin is now *ready* for production πŸŽ‰. +This means that we have addressed the top issues filed by the community since the first release of the plugin. + +### Android + +* 🎹 We fixed all known keyboard, and accessibility issues: +https://github.com/flutter/flutter/issues/19418, +https://github.com/flutter/flutter/issues/41089, +https://github.com/flutter/flutter/issues/50716, +https://github.com/flutter/flutter/issues/36478, +https://github.com/flutter/flutter/issues/52211, +https://github.com/flutter/flutter/issues/37989, +https://github.com/flutter/flutter/issues/51254, +https://github.com/flutter/flutter/issues/50716, +https://github.com/flutter/flutter/issues/51915, +https://github.com/flutter/flutter/issues/55724, +https://github.com/flutter/flutter/issues/56513, +https://github.com/flutter/flutter/issues/56515, +https://github.com/flutter/flutter/issues/61085, +https://github.com/flutter/flutter/issues/62205, +https://github.com/flutter/flutter/issues/62547, +https://github.com/flutter/flutter/issues/58943, +https://github.com/flutter/flutter/issues/56361, +https://github.com/flutter/flutter/issues/42902, +https://github.com/flutter/flutter/issues/40716, +https://github.com/flutter/flutter/issues/39880, +https://github.com/flutter/flutter/issues/37989, +https://github.com/flutter/flutter/issues/27924. + +* βœ… Text selection: https://github.com/flutter/flutter/issues/24585, https://github.com/flutter/flutter/issues/24584. + +* 🌎 API level: `WebView` just requires API level 19 (It used to be 20): https://github.com/flutter/flutter/issues/23728. + +* ⚑️ Performance: https://github.com/flutter/flutter/issues/61280, https://github.com/flutter/flutter/issues/31243. + +To get these fixes, set `WebView.platform = SurfaceAndroidWebView();` in `initState()`. For example: ```dart import 'dart:io'; +import 'package:webview_flutter/webview_flutter.dart'; + class WebViewExample extends StatefulWidget { @override void initState() { @@ -22,6 +58,14 @@ class WebViewExample extends StatefulWidget { } ``` +### iOS + +* πŸ“± It's no longer required to add the `io.flutter.embedded_views_preview` to `Info.plist` since +platform views are enabled by default: https://github.com/flutter/flutter/issues/57067. +In previous versions, importing `WebView` required an expensive thread configuration even before the +`WebView` was rendered. In 1.0.0, this thread configuration only takes place when the `WebView` is +rendered. + ## 0.3.24 * Keep handling deprecated Android v1 classes for backward compatibility. diff --git a/packages/webview_flutter/README.md b/packages/webview_flutter/README.md index c86993a15a09..88005293149e 100644 --- a/packages/webview_flutter/README.md +++ b/packages/webview_flutter/README.md @@ -1,4 +1,4 @@ -# WebView for Flutter (Developers Preview) +# WebView for Flutter [![pub package](https://img.shields.io/pub/v/webview_flutter.svg)](https://pub.dartlang.org/packages/webview_flutter) @@ -7,30 +7,55 @@ A Flutter plugin that provides a WebView widget. On iOS the WebView widget is backed by a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview); On Android the WebView widget is backed by a [WebView](https://developer.android.com/reference/android/webkit/WebView). -## Developers Preview Status -The plugin relies on Flutter's new mechanism for embedding Android and iOS views. -As that mechanism is currently in a developers preview, this plugin should also be -considered a developers preview. +**The WebView plugin has reached [1.0.0](/link-to-release-notes), and it's now *ready* for production.** -Known issues are tagged with the [platform-views](https://github.com/flutter/flutter/labels/a%3A%20platform-views) and/or [webview](https://github.com/flutter/flutter/labels/p%3A%20webview) labels. +## Usage +Add `webview_flutter` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). -To use this plugin on iOS you need to opt-in for the embedded views preview by -adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` -and the value `YES`. +See the [WebView](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebView-class.html) +widget's Dartdoc for more details on how to use the widget. -## Keyboard support - not ready for production use -Keyboard support within webviews is experimental. The Android version relies on some low-level knobs that have not been well tested -on a broad spectrum of devices yet, and therefore **it is not recommended to rely on webview keyboard in production apps yet**. -See the [webview-keyboard](https://github.com/flutter/flutter/issues?q=is%3Aopen+is%3Aissue+label%3A%22p%3A+webview-keyboard%22) for known issues with keyboard input. +### Android -## Setup +There are two implementations of the underlying primitive called [Platform Views](https://flutter.dev/docs/development/platform-integration/platform-views). -### iOS -Opt-in to the embedded views preview by adding a boolean property to the app's `Info.plist` file -with the key `io.flutter.embedded_views_preview` and the value `YES`. +Prior to 1.0.0, WebView only used an Android [VirtualDisplay](https://github.com/flutter/flutter/wiki/Android-Platform-Views#the-approach). +While this implementation provides the best average rendering performance, it introduced [keyboard and accesibility issues](https://github.com/flutter/flutter/wiki/Android-Platform-Views#associated-problems-and-workarounds) +that were hard to fix. In 1.0.0, the WebView also uses [Hybrid composition](https://github.com/flutter/flutter/wiki/Hybrid-Composition#android), +which enables the WebView to be embedded in the Android view hierarchy. -## Usage -Add `webview_flutter` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). +To enable hybrid composition, set `WebView.platform = SurfaceAndroidWebView();` in `initState()`. For example: + +```dart +import 'dart:io'; + +import 'package:webview_flutter/webview_flutter.dart'; + +class WebViewExample extends StatefulWidget { + @override + void initState() { + super.initState(); + if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); + } + + @override + Widget build(BuildContext context) { + return WebView( + initialUrl: 'https://flutter.dev', + ); + } +} +``` + +Prior to Android 10, Hybrid composition performs a device-host-device copy of the Flutter texture. In general, reducing Flutter animations while the WebView is rendered helps improve performance. However, we recommend testing your app with the devices and Android versions typically used by your users. + +`SurfaceAndroidWebView()` requires [API level 19](https://developer.android.com/studio/releases/platforms?hl=th#4.4). The plugin itself doesn't enforce the API level, so if you want to make the app available on devices running this API level or above, add the following to `/android/app/build.gradle`: -You can now include a WebView widget in your widget tree. -See the WebView widget's Dartdoc for more details on how to use the widget. +```gradle +android { + defaultConfig { + // Required by the Flutter WebView plugin. + minSdkVersion 19 + } + } +``` diff --git a/packages/webview_flutter/example/ios/Runner/Info.plist b/packages/webview_flutter/example/ios/Runner/Info.plist index 94f5857376a2..a810c5a172c0 100644 --- a/packages/webview_flutter/example/ios/Runner/Info.plist +++ b/packages/webview_flutter/example/ios/Runner/Info.plist @@ -39,8 +39,6 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - io.flutter.embedded_views_preview - UIViewControllerBasedStatusBarAppearance diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 483bd39c1739..247f32ba6d6b 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 0.4.0 +version: 1.0.0 homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter environment: From f56cdd5843bc2eba56ec2b357c58af5ee56a9858 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Sep 2020 13:30:44 -0700 Subject: [PATCH 11/14] update changelog and readme --- packages/webview_flutter/CHANGELOG.md | 80 +++++---------------------- packages/webview_flutter/README.md | 27 +++++---- 2 files changed, 28 insertions(+), 79 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index a0161a632907..f32724589020 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,70 +1,16 @@ -## 1.0.0 - -We are happy to announce that the WebView plugin is now *ready* for production πŸŽ‰. -This means that we have addressed the top issues filed by the community since the first release of the plugin. - -### Android - -* 🎹 We fixed all known keyboard, and accessibility issues: -https://github.com/flutter/flutter/issues/19418, -https://github.com/flutter/flutter/issues/41089, -https://github.com/flutter/flutter/issues/50716, -https://github.com/flutter/flutter/issues/36478, -https://github.com/flutter/flutter/issues/52211, -https://github.com/flutter/flutter/issues/37989, -https://github.com/flutter/flutter/issues/51254, -https://github.com/flutter/flutter/issues/50716, -https://github.com/flutter/flutter/issues/51915, -https://github.com/flutter/flutter/issues/55724, -https://github.com/flutter/flutter/issues/56513, -https://github.com/flutter/flutter/issues/56515, -https://github.com/flutter/flutter/issues/61085, -https://github.com/flutter/flutter/issues/62205, -https://github.com/flutter/flutter/issues/62547, -https://github.com/flutter/flutter/issues/58943, -https://github.com/flutter/flutter/issues/56361, -https://github.com/flutter/flutter/issues/42902, -https://github.com/flutter/flutter/issues/40716, -https://github.com/flutter/flutter/issues/39880, -https://github.com/flutter/flutter/issues/37989, -https://github.com/flutter/flutter/issues/27924. - -* βœ… Text selection: https://github.com/flutter/flutter/issues/24585, https://github.com/flutter/flutter/issues/24584. - -* 🌎 API level: `WebView` just requires API level 19 (It used to be 20): https://github.com/flutter/flutter/issues/23728. - -* ⚑️ Performance: https://github.com/flutter/flutter/issues/61280, https://github.com/flutter/flutter/issues/31243. - -To get these fixes, set `WebView.platform = SurfaceAndroidWebView();` in `initState()`. For example: - -```dart -import 'dart:io'; - -import 'package:webview_flutter/webview_flutter.dart'; - -class WebViewExample extends StatefulWidget { - @override - void initState() { - super.initState(); - if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); - } - - @override - Widget build(BuildContext context) { - return WebView( - initialUrl: 'https://flutter.dev', - ); - } -} -``` - -### iOS - -* πŸ“± It's no longer required to add the `io.flutter.embedded_views_preview` to `Info.plist` since -platform views are enabled by default: https://github.com/flutter/flutter/issues/57067. -In previous versions, importing `WebView` required an expensive thread configuration even before the -`WebView` was rendered. In 1.0.0, this thread configuration only takes place when the `WebView` is -rendered. +## 1.0.0 - Out of developer preview πŸŽ‰. + +* Bumped the minimal Flutter SDK to 1.22 where platform views are out of developer preview, and +performing better on iOS. Flutter 1.22 no longer requires adding the +`io.flutter.embedded_views_preview` flag to `Info.plist`. + +* Added support for Hybrid Composition on Android (see opt-in instructions in [README](https://github.com/flutter/plugins/blob/master/packages/webview_flutter/README.md#android)) + * Lowered the required Android API to 19 (was previously 20): [#23728](https://github.com/flutter/flutter/issues/23728). + * Fixed the following issues: + * 🎹 Keyboard: [#41089](https://github.com/flutter/flutter/issues/41089), [#36478](https://github.com/flutter/flutter/issues/36478), [#51254](https://github.com/flutter/flutter/issues/51254), [#50716](https://github.com/flutter/flutter/issues/50716), [#55724](https://github.com/flutter/flutter/issues/55724), [#56513](https://github.com/flutter/flutter/issues/56513), [#56515](https://github.com/flutter/flutter/issues/56515), [#61085](https://github.com/flutter/flutter/issues/61085), [#62205](https://github.com/flutter/flutter/issues/62205), [#62547](https://github.com/flutter/flutter/issues/62547), [#58943](https://github.com/flutter/flutter/issues/58943), [#56361](https://github.com/flutter/flutter/issues/56361), [#56361](https://github.com/flutter/flutter/issues/42902), [#40716](https://github.com/flutter/flutter/issues/40716), [#37989](https://github.com/flutter/flutter/issues/37989), [#27924](https://github.com/flutter/flutter/issues/27924). + * ♿️ Accessibility: [#50716](https://github.com/flutter/flutter/issues/50716). + * ⚑️ Performance: [#61280](https://github.com/flutter/flutter/issues/61280), [#31243](https://github.com/flutter/flutter/issues/31243), [#52211](https://github.com/flutter/flutter/issues/52211). + * πŸ“Ή Video: [#5191](https://github.com/flutter/flutter/issues/5191). ## 0.3.24 diff --git a/packages/webview_flutter/README.md b/packages/webview_flutter/README.md index 88005293149e..c7b55f1c89dd 100644 --- a/packages/webview_flutter/README.md +++ b/packages/webview_flutter/README.md @@ -7,24 +7,29 @@ A Flutter plugin that provides a WebView widget. On iOS the WebView widget is backed by a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview); On Android the WebView widget is backed by a [WebView](https://developer.android.com/reference/android/webkit/WebView). -**The WebView plugin has reached [1.0.0](/link-to-release-notes), and it's now *ready* for production.** - ## Usage Add `webview_flutter` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). -See the [WebView](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebView-class.html) +You can now include a WebView widget in your widget tree. See the +[WebView](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebView-class.html) widget's Dartdoc for more details on how to use the widget. -### Android -There are two implementations of the underlying primitive called [Platform Views](https://flutter.dev/docs/development/platform-integration/platform-views). -Prior to 1.0.0, WebView only used an Android [VirtualDisplay](https://github.com/flutter/flutter/wiki/Android-Platform-Views#the-approach). -While this implementation provides the best average rendering performance, it introduced [keyboard and accesibility issues](https://github.com/flutter/flutter/wiki/Android-Platform-Views#associated-problems-and-workarounds) -that were hard to fix. In 1.0.0, the WebView also uses [Hybrid composition](https://github.com/flutter/flutter/wiki/Hybrid-Composition#android), -which enables the WebView to be embedded in the Android view hierarchy. +## Android Platform Views +The WebView is relying on +[Platform Views](https://flutter.dev/docs/development/platform-integration/platform-views) to embed +the Android’s webview within the Flutter app. By default a Virtual Display based platform view +backend is used, this implementation has multiple +[keyboard](https://github.com/flutter/flutter/issues?q=is%3Aopen+label%3Avd-only+label%3A%22p%3A+webview-keyboard%22). +When keyboard input is required we recommend using the Hybrid Composition based platform views +implementation. Note that on Android versions prior to Android 10 Hybrid Composition has some +[performance drawbacks](https://flutter.dev/docs/development/platform-integration/platform-views#performance). + +### Using Hybrid Composition -To enable hybrid composition, set `WebView.platform = SurfaceAndroidWebView();` in `initState()`. For example: +To enable hybrid composition, set `WebView.platform = SurfaceAndroidWebView();` in `initState()`. +For example: ```dart import 'dart:io'; @@ -47,8 +52,6 @@ class WebViewExample extends StatefulWidget { } ``` -Prior to Android 10, Hybrid composition performs a device-host-device copy of the Flutter texture. In general, reducing Flutter animations while the WebView is rendered helps improve performance. However, we recommend testing your app with the devices and Android versions typically used by your users. - `SurfaceAndroidWebView()` requires [API level 19](https://developer.android.com/studio/releases/platforms?hl=th#4.4). The plugin itself doesn't enforce the API level, so if you want to make the app available on devices running this API level or above, add the following to `/android/app/build.gradle`: ```gradle From ab69759f3b05d1bb8eb0a51394f05fd25dc44ac0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Sep 2020 13:37:44 -0700 Subject: [PATCH 12/14] set to pre --- packages/webview_flutter/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 247f32ba6d6b..6638f1d7ad11 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutte environment: sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.22.0" + flutter: ">=1.22.0-10.0.pre <2.0.0" dependencies: flutter: From 1f0b01d0fbb4bb49cf375f1eecacfefc67e724a2 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Sep 2020 14:04:46 -0700 Subject: [PATCH 13/14] Change back to what Im feeling --- packages/webview_flutter/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 6638f1d7ad11..247f32ba6d6b 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutte environment: sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.22.0-10.0.pre <2.0.0" + flutter: ">=1.22.0" dependencies: flutter: From ff8dfb98dfcc11da08ec2781a3edc24c6dfb8cf7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Sep 2020 14:08:49 -0700 Subject: [PATCH 14/14] add upper bound --- packages/webview_flutter/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 247f32ba6d6b..aa9c606a5688 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutte environment: sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.22.0" + flutter: ">=1.22.0 <2.0.0" dependencies: flutter: