Skip to content

Commit

Permalink
fix #1173
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed May 5, 2022
1 parent 1fbabf1 commit a6cb410
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.pichillilorenzo.flutter_inappwebview.types;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class URLRequest {
@NonNull
@Nullable
private String url;
@Nullable
private String method;
Expand All @@ -17,7 +16,7 @@ public class URLRequest {
@Nullable
private Map<String, String> headers;

public URLRequest(@NonNull String url, @Nullable String method, @Nullable byte[] body, @Nullable Map<String, String> headers) {
public URLRequest(@Nullable String url, @Nullable String method, @Nullable byte[] body, @Nullable Map<String, String> headers) {
this.url = url;
this.method = method;
this.body = body;
Expand All @@ -30,10 +29,12 @@ public static URLRequest fromMap(@Nullable Map<String, Object> map) {
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<String, String> headers = (Map<String, String>) map.get("headers");
assert url != null;
return new URLRequest(url, method, body, headers);
}

Expand All @@ -45,12 +46,12 @@ public Map<String, Object> toMap() {
return urlRequestMap;
}

@NonNull
@Nullable
public String getUrl() {
return url;
}

public void setUrl(@NonNull String url) {
public void setUrl(@Nullable String url) {
this.url = url;
}

Expand Down Expand Up @@ -88,15 +89,15 @@ public boolean equals(Object o) {

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;
}

@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);
Expand Down
18 changes: 18 additions & 0 deletions example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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
7 changes: 4 additions & 3 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 5 additions & 2 deletions ios/Classes/Types/URLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit a6cb410

Please sign in to comment.