From a6cb4105b11ad6ccd23404981d75e03ed2d6525d Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Thu, 5 May 2022 21:46:14 +0200 Subject: [PATCH] fix #1173 --- CHANGELOG.md | 4 ++++ .../flutter_inappwebview/types/URLRequest.java | 17 +++++++++-------- example/ios/Flutter/Flutter.podspec | 18 ++++++++++++++++++ .../ios/Flutter/flutter_export_environment.sh | 7 ++++--- ios/Classes/Types/URLRequest.swift | 7 +++++-- lib/src/types.dart | 2 +- pubspec.yaml | 2 +- 7 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 example/ios/Flutter/Flutter.podspec diff --git a/CHANGELOG.md b/CHANGELOG.md index 477b18f0..b6b18dc5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.4.3+6 + +- Fixed "iOS flutter_inappwebview/URLRequest.swift:13: Fatal error: Unexpectedly found nil while unwrapping an Optional value" [#1173](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1173) + ## 5.4.3+5 - Fixed possible java.lang.NullPointerException in `Runnable` of `InputAwareWebView.setInputConnectionTarget` method diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/URLRequest.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/URLRequest.java index 5dd33c14..e4037775 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/URLRequest.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/URLRequest.java @@ -1,6 +1,5 @@ package com.pichillilorenzo.flutter_inappwebview.types; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import java.util.Arrays; @@ -8,7 +7,7 @@ import java.util.HashMap; import java.util.Map; public class URLRequest { - @NonNull + @Nullable private String url; @Nullable private String method; @@ -17,7 +16,7 @@ public class URLRequest { @Nullable private Map headers; - public URLRequest(@NonNull String url, @Nullable String method, @Nullable byte[] body, @Nullable Map headers) { + public URLRequest(@Nullable String url, @Nullable String method, @Nullable byte[] body, @Nullable Map headers) { this.url = url; this.method = method; this.body = body; @@ -30,10 +29,12 @@ public class URLRequest { return null; } String url = (String) map.get("url"); + if (url == null) { + url = "about:blank"; + } String method = (String) map.get("method"); byte[] body = (byte[]) map.get("body"); Map headers = (Map) map.get("headers"); - assert url != null; return new URLRequest(url, method, body, headers); } @@ -45,12 +46,12 @@ public class URLRequest { return urlRequestMap; } - @NonNull + @Nullable public String getUrl() { return url; } - public void setUrl(@NonNull String url) { + public void setUrl(@Nullable String url) { this.url = url; } @@ -88,7 +89,7 @@ public class URLRequest { URLRequest that = (URLRequest) o; - if (!url.equals(that.url)) return false; + if (url != null ? !url.equals(that.url) : that.url != null) return false; if (method != null ? !method.equals(that.method) : that.method != null) return false; if (!Arrays.equals(body, that.body)) return false; return headers != null ? headers.equals(that.headers) : that.headers == null; @@ -96,7 +97,7 @@ public class URLRequest { @Override public int hashCode() { - int result = url.hashCode(); + int result = url != null ? url.hashCode() : 0; result = 31 * result + (method != null ? method.hashCode() : 0); result = 31 * result + Arrays.hashCode(body); result = 31 * result + (headers != null ? headers.hashCode() : 0); diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec new file mode 100644 index 00000000..663d5b29 --- /dev/null +++ b/example/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# NOTE: This podspec is NOT to be published. It is only used as a local source! +# This is a generated file; do not edit or check into version control. +# + +Pod::Spec.new do |s| + s.name = 'Flutter' + s.version = '1.0.0' + s.summary = 'High-performance, high-fidelity mobile apps.' + s.homepage = 'https://flutter.io' + s.license = { :type => 'MIT' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } + s.ios.deployment_target = '9.0' + # Framework linking is handled by Flutter tooling, not CocoaPods. + # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. + s.vendored_frameworks = 'path/to/nothing' +end diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index a7327a33..de544d92 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -3,11 +3,12 @@ export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4" export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/flutter_inappwebview_v5/example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" -export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_TARGET=integration_test/webview_flutter_test.dart" export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" +export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" export "DART_OBFUSCATION=false" -export "TRACK_WIDGET_CREATION=false" +export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=.packages" +export "PACKAGE_CONFIG=/Users/lorenzopichilli/flutter_inappwebview_v5/example/.dart_tool/package_config.json" diff --git a/ios/Classes/Types/URLRequest.swift b/ios/Classes/Types/URLRequest.swift index efaf3e3c..86704686 100644 --- a/ios/Classes/Types/URLRequest.swift +++ b/ios/Classes/Types/URLRequest.swift @@ -9,8 +9,11 @@ import Foundation extension URLRequest { public init(fromPluginMap: [String:Any?]) { - let url = fromPluginMap["url"] as! String - self.init(url: URL(string: url)!) + if let urlString = fromPluginMap["url"] as? String, let url = URL(string: urlString) { + self.init(url: url) + } else { + self.init(url: URL(string: "about:blank")!) + } if let method = fromPluginMap["method"] as? String { httpMethod = method diff --git a/lib/src/types.dart b/lib/src/types.dart index 198777cb..be9eebb3 100755 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -6328,7 +6328,7 @@ class IOSShouldAllowDeprecatedTLSAction { ///A URL load request that is independent of protocol or URL scheme. class URLRequest { - ///The URL of the request. + ///The URL of the request. Setting this to `null` will load `about:blank`. Uri? url; ///The HTTP request method. diff --git a/pubspec.yaml b/pubspec.yaml index acc70580..56c02568 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: 5.4.3+5 +version: 5.4.3+6 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: