From 477b94e03f4975e59ef20526d759245dae335f3d Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Mon, 22 Jun 2020 01:17:35 +0200 Subject: [PATCH] Update README.md, Update missing docs, Fix pub.dev Health suggestions and Analysis suggestions, v3.4.0+1 --- CHANGELOG.md | 6 +++++ README.md | 16 +++++++++++++ example/.flutter-plugins-dependencies | 2 +- flutter_inappwebview.iml | 1 - lib/src/X509Certificate/asn1_decoder.dart | 5 ++++ lib/src/X509Certificate/asn1_identifier.dart | 4 ++++ lib/src/in_app_browser.dart | 1 - lib/src/in_app_webview_controller.dart | 12 ++++++---- lib/src/types.dart | 5 ++-- lib/src/web_storage.dart | 25 ++++++++++++++++++++ lib/src/webview.dart | 4 ++-- pubspec.yaml | 2 +- 12 files changed, 71 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c98fa8e..d05bf1d1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 3.4.0+1 + +- Update README.md +- Update missing docs +- Fix pub.dev Health suggestions and Analysis suggestions + ## 3.4.0 - Added `requestFocusNodeHref`, `requestImageRef`, `getMetaTags`, `getMetaThemeColor`, `getScrollX`, `getScrollY`, `getCertificate` webview methods diff --git a/README.md b/README.md index 1e283b34..7885835a 100755 --- a/README.md +++ b/README.md @@ -412,8 +412,24 @@ Screenshots: * `getMetaThemeColor`: Returns an instance of `Color` representing the `content` value of the `` tag of the current WebView, if available, otherwise `null`. * `getScrollX`: Returns the scrolled left position of the current WebView. * `getScrollY`: Returns the scrolled top position of the current WebView. +* `getCertificate`: Gets the SSL certificate for the main top-level page or null if there is no certificate (the site is not secure). * `static getDefaultUserAgent`: Gets the default user agent. +##### `InAppWebViewController.webStorage` + +`InAppWebViewController.webStorage` provides access to the JavaScript [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API): +* `WebStorage.localStorage`: provides access to `window.localStorage`; +* `WebStorage.sessionStorage`: provides access to `window.localStorage`. + +Methods available: +* `length`: Returns an integer representing the number of data items stored in the Storage object. +* `setItem({@required String key, @required dynamic value})`: When passed a `key` name and `value`, will add that key to the storage, or update that key's value if it already exists. +* `getItem({@required String key})`: When passed a `key` name, will return that key's value, or `null` if the key does not exist, in the given Storage object. +* `removeItem({@required String key})`: When passed a `key` name, will remove that key from the given Storage object if it exists. +* `getItems`: Returns the list of all items from the given Storage object. +* `clear`: Clears all keys stored in a given Storage object. +* `key({@required int index})`: When passed a number `index`, returns the name of the nth key in a given Storage object. + ##### `InAppWebViewController` Android-specific methods Android-specific methods can be called using the `InAppWebViewController.android` attribute. diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 9267504a..fd4efc3c 100755 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"android":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[]},"dependencyGraph":[{"name":"e2e","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-06-22 00:03:09.205244","version":"1.17.4"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"android":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[]},"dependencyGraph":[{"name":"e2e","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-06-22 00:25:30.717386","version":"1.17.4"} \ No newline at end of file diff --git a/flutter_inappwebview.iml b/flutter_inappwebview.iml index c8905c93..111d60ac 100755 --- a/flutter_inappwebview.iml +++ b/flutter_inappwebview.iml @@ -26,7 +26,6 @@ - diff --git a/lib/src/X509Certificate/asn1_decoder.dart b/lib/src/X509Certificate/asn1_decoder.dart index e47d8c85..13aecef8 100644 --- a/lib/src/X509Certificate/asn1_decoder.dart +++ b/lib/src/X509Certificate/asn1_decoder.dart @@ -242,7 +242,9 @@ class ASN1DERDecoder { // if YY >= 50 use 19xx, if YY < 50 use 20xx var year = int.parse(utc.substring(0, 2), radix: 10); year = (year >= 50) ? 1900 + year : 2000 + year; + // ignore: non_constant_identifier_names var MM = int.parse(utc.substring(2, 4), radix: 10); + // ignore: non_constant_identifier_names var DD = int.parse(utc.substring(4, 6), radix: 10); var hh = int.parse(utc.substring(6, 8), radix: 10); var mm = int.parse(utc.substring(8, 10), radix: 10); @@ -328,8 +330,11 @@ class ASN1DERDecoder { } // if YY >= 50 use 19xx, if YY < 50 use 20xx + // ignore: non_constant_identifier_names var YYYY = int.parse(gentime.substring(0, 4), radix: 10); + // ignore: non_constant_identifier_names var MM = int.parse(gentime.substring(4, 6), radix: 10); + // ignore: non_constant_identifier_names var DD = int.parse(gentime.substring(6, 8), radix: 10); var hh = int.parse(gentime.substring(8, 10), radix: 10); var mm = int.parse(gentime.substring(10, 12), radix: 10); diff --git a/lib/src/X509Certificate/asn1_identifier.dart b/lib/src/X509Certificate/asn1_identifier.dart index 251bee67..f2086f1f 100644 --- a/lib/src/X509Certificate/asn1_identifier.dart +++ b/lib/src/X509Certificate/asn1_identifier.dart @@ -25,6 +25,7 @@ class ASN1IdentifierClass { static const CONTEXT_SPECIFIC = const ASN1IdentifierClass._internal(0x80); static const PRIVATE = const ASN1IdentifierClass._internal(0xC0); + @override String toString() { switch (this.toValue()) { case 0x00: @@ -36,6 +37,7 @@ class ASN1IdentifierClass { case 0xC0: return "PRIVATE"; } + return ""; } bool operator ==(value) => value == _value; @@ -123,6 +125,7 @@ class ASN1IdentifierTagNumber { static const CHARACTER_STRING = const ASN1IdentifierTagNumber._internal(0x1D); static const BMP_STRING = const ASN1IdentifierTagNumber._internal(0x1E); + @override String toString() { switch (this.toValue()) { case 0x00: @@ -184,6 +187,7 @@ class ASN1IdentifierTagNumber { case 0x1E: return "BMP_STRING"; } + return ""; } bool operator ==(value) => value == _value; diff --git a/lib/src/in_app_browser.dart b/lib/src/in_app_browser.dart index a53c9693..f5ceac33 100755 --- a/lib/src/in_app_browser.dart +++ b/lib/src/in_app_browser.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:collection'; -import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; diff --git a/lib/src/in_app_webview_controller.dart b/lib/src/in_app_webview_controller.dart index 42567c7c..3c3bea85 100644 --- a/lib/src/in_app_webview_controller.dart +++ b/lib/src/in_app_webview_controller.dart @@ -50,7 +50,10 @@ class InAppWebViewController { // ignore: unused_field dynamic _id; + + // ignore: unused_field String _inAppBrowserUuid; + InAppBrowser _inAppBrowser; ///Android controller that contains only android-specific methods @@ -59,6 +62,7 @@ class InAppWebViewController { ///iOS controller that contains only ios-specific methods IOSInAppWebViewController ios; + ///Provides access to the JavaScript [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API): `window.sessionStorage` and `window.localStorage`. WebStorage webStorage; InAppWebViewController(dynamic id, WebView webview) { @@ -233,9 +237,9 @@ class InAppWebViewController { case "onGeolocationPermissionsHidePrompt": if (_webview != null && _webview.androidOnGeolocationPermissionsHidePrompt != null) - await _webview.androidOnGeolocationPermissionsHidePrompt(this); + _webview.androidOnGeolocationPermissionsHidePrompt(this); else if (_inAppBrowser != null) - await _inAppBrowser.androidOnGeolocationPermissionsHidePrompt(); + _inAppBrowser.androidOnGeolocationPermissionsHidePrompt(); break; case "shouldInterceptRequest": String url = call.arguments["url"]; @@ -955,7 +959,7 @@ class InAppWebViewController { var faviconUrl = url.scheme + "://" + url.host + "/favicon.ico"; await client.headUrl(Uri.parse(faviconUrl)); favicons.add(Favicon(url: faviconUrl, rel: "shortcut icon")); - } catch (e, stacktrace) { + } catch (e) { print("/favicon.ico file not found: " + e.toString()); // print(stacktrace); } @@ -972,7 +976,7 @@ class InAppWebViewController { manifestResponse = await manifestRequest.close(); manifestFound = manifestResponse.statusCode == 200 && manifestResponse.headers.contentType?.mimeType == "application/json"; - } catch (e, stacktrace) { + } catch (e) { print("Manifest file not found: " + e.toString()); // print(stacktrace); } diff --git a/lib/src/types.dart b/lib/src/types.dart index a1196a42..aa895db8 100755 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -970,8 +970,6 @@ class ServerTrustChallenge { IOSSslError iosError; ///The message associated to the [androidError]/[iosError]. - /// - ///**NOTE**: on iOS this value is always an empty string. String message; ///The SSL certificate used for this challenge. @@ -4129,8 +4127,11 @@ class SslCertificateDName { SslCertificateDName( // ignore: non_constant_identifier_names {this.CName = "", + // ignore: non_constant_identifier_names this.DName = "", + // ignore: non_constant_identifier_names this.OName = "", + // ignore: non_constant_identifier_names this.UName = ""}); static SslCertificateDName fromMap(Map map) { diff --git a/lib/src/web_storage.dart b/lib/src/web_storage.dart index 8165ab03..560065f3 100644 --- a/lib/src/web_storage.dart +++ b/lib/src/web_storage.dart @@ -5,15 +5,23 @@ import 'package:flutter/foundation.dart'; import 'in_app_webview_controller.dart'; import 'types.dart'; +///Class that provides access to the JavaScript [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API): `window.sessionStorage` and `window.localStorage`. +///It used by [InAppWebViewController.webStorage]. class WebStorage { + ///Represents `window.localStorage`. LocalStorage localStorage; + + ///Represents `window.sessionStorage`. SessionStorage sessionStorage; WebStorage({@required this.localStorage, @required this.sessionStorage}); } +///Class that represents a single web storage item of the JavaScript `window.sessionStorage` and `window.localStorage` objects. class WebStorageItem { + ///Item key. String key; + ///Item value. dynamic value; WebStorageItem({this.key, this.value}); @@ -35,8 +43,13 @@ class WebStorageItem { } } +///Class that provides methods to manage the JavaScript [Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) object. +///It is used by [LocalStorage] and [SessionStorage]. class Storage { + InAppWebViewController _controller; + + ///The web storage type: `window.sessionStorage` or `window.localStorage`. WebStorageType webStorageType; Storage(InAppWebViewController controller, this.webStorageType) { @@ -44,6 +57,7 @@ class Storage { this._controller = controller; } + ///Returns an integer representing the number of data items stored in the Storage object. Future length() async { var result = await _controller.evaluateJavascript(source: """ window.$webStorageType.length; @@ -51,6 +65,7 @@ class Storage { return result != null ? int.parse(json.decode(result)) : null; } + ///When passed a [key] name and [value], will add that key to the storage, or update that key's value if it already exists. Future setItem({@required String key, @required dynamic value}) async { var encodedValue = json.encode(value); await _controller.evaluateJavascript(source: """ @@ -58,6 +73,7 @@ class Storage { """); } + ///When passed a [key] name, will return that key's value, or `null` if the key does not exist, in the given Storage object. Future getItem({@required String key}) async { var itemValue = await _controller.evaluateJavascript(source: """ window.$webStorageType.getItem("$key"); @@ -74,12 +90,14 @@ class Storage { return itemValue; } + ///When passed a [key] name, will remove that key from the given Storage object if it exists. Future removeItem({@required String key}) async { await _controller.evaluateJavascript(source: """ window.$webStorageType.removeItem("$key"); """); } + ///Returns the list of all items from the given Storage object. Future> getItems() async { var webStorageItems = []; @@ -112,12 +130,15 @@ class Storage { return webStorageItems; } + ///Clears all keys stored in a given Storage object. Future clear() async { await _controller.evaluateJavascript(source: """ window.$webStorageType.clear(); """); } + ///When passed a number [index], returns the name of the nth key in a given Storage object. + ///The order of keys is user-agent defined, so you should not rely on it. Future key({@required int index}) async { var result = await _controller.evaluateJavascript(source: """ window.$webStorageType.key($index); @@ -126,11 +147,15 @@ class Storage { } } +///Class that provides methods to manage the JavaScript `window.localStorage` object. +///It used by [WebStorage]. class LocalStorage extends Storage { LocalStorage(InAppWebViewController controller) : super(controller, WebStorageType.LOCAL_STORAGE); } +///Class that provides methods to manage the JavaScript `window.sessionStorage` object. +///It used by [WebStorage]. class SessionStorage extends Storage { SessionStorage(InAppWebViewController controller) : super(controller, WebStorageType.SESSION_STORAGE); diff --git a/lib/src/webview.dart b/lib/src/webview.dart index 228952c9..19228c1b 100644 --- a/lib/src/webview.dart +++ b/lib/src/webview.dart @@ -1,4 +1,4 @@ -import 'package:flutter_inappwebview/src/context_menu.dart'; +import 'context_menu.dart'; import 'types.dart'; import 'in_app_webview_controller.dart'; @@ -365,7 +365,7 @@ abstract class WebView { ///**NOTE**: available only on Android. /// ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebChromeClient#onGeolocationPermissionsHidePrompt() - final Future Function(InAppWebViewController controller) + final void Function(InAppWebViewController controller) androidOnGeolocationPermissionsHidePrompt; ///Notify the host application of a resource request and allow the application to return the data. diff --git a/pubspec.yaml b/pubspec.yaml index 538b8947..a4f35591 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. -version: 3.4.0 +version: 3.4.0+1 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: