From 1f3318bed81737badaadd95d6b4aa6cc4df5fada Mon Sep 17 00:00:00 2001 From: AlexVincent525 Date: Fri, 17 Jan 2020 13:35:16 +0800 Subject: [PATCH 1/3] Fix crash on nil/invalid url. --- ios/Classes/FlutterWebViewController.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ios/Classes/FlutterWebViewController.swift b/ios/Classes/FlutterWebViewController.swift index da156e6e..3b3c7597 100755 --- a/ios/Classes/FlutterWebViewController.swift +++ b/ios/Classes/FlutterWebViewController.swift @@ -98,14 +98,16 @@ public class FlutterWebViewController: FlutterMethodCallDelegate, FlutterPlatfor } if initialData != nil { - let data = (initialData!["data"] as? String)! - let mimeType = (initialData!["mimeType"] as? String)! - let encoding = (initialData!["encoding"] as? String)! - let baseUrl = (initialData!["baseUrl"] as? String)! + let data = (initialData!["data"])! + let mimeType = (initialData!["mimeType"])! + let encoding = (initialData!["encoding"])! + let baseUrl = (initialData!["baseUrl"])! webView!.loadData(data: data, mimeType: mimeType, encoding: encoding, baseUrl: baseUrl) } else { - webView!.loadUrl(url: URL(string: initialUrl)!, headers: initialHeaders) + if let url = URL(string: initialUrl) { + webView!.loadUrl(url: url, headers: initialHeaders) + } } } @@ -347,7 +349,7 @@ public class FlutterWebViewController: FlutterMethodCallDelegate, FlutterPlatfor case "printCurrentPage": if webView != nil { webView!.printCurrentPage(printCompletionHandler: {(completed, error) in - if !completed, let e = error { + if !completed, let _ = error { result(false) return } From b2ad0a29449fec580ee133ca77ebf6670c6f8b8c Mon Sep 17 00:00:00 2001 From: AlexVincent525 Date: Fri, 17 Jan 2020 13:49:03 +0800 Subject: [PATCH 2/3] Parse url before create platform view. --- lib/src/in_app_webview.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/in_app_webview.dart b/lib/src/in_app_webview.dart index 56e1a774..e47c1e09 100755 --- a/lib/src/in_app_webview.dart +++ b/lib/src/in_app_webview.dart @@ -383,7 +383,7 @@ class _InAppWebViewState extends State { gestureRecognizers: widget.gestureRecognizers, layoutDirection: TextDirection.rtl, creationParams: { - 'initialUrl': widget.initialUrl, + 'initialUrl': Uri.parse(widget.initialUrl), 'initialFile': widget.initialFile, 'initialData': widget.initialData?.toMap(), 'initialHeaders': widget.initialHeaders, @@ -416,7 +416,7 @@ class _InAppWebViewState extends State { onPlatformViewCreated: _onPlatformViewCreated, gestureRecognizers: widget.gestureRecognizers, creationParams: { - 'initialUrl': widget.initialUrl, + 'initialUrl': Uri.parse(widget.initialUrl), 'initialFile': widget.initialFile, 'initialData': widget.initialData?.toMap(), 'initialHeaders': widget.initialHeaders, From 86b05967e7c9017f4ea790a2dbbcb1ff2fad9c2a Mon Sep 17 00:00:00 2001 From: AlexVincent525 Date: Wed, 29 Jan 2020 21:19:17 +0800 Subject: [PATCH 3/3] Update parsed uri into string to avoid wrong type match. --- lib/src/in_app_webview.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/in_app_webview.dart b/lib/src/in_app_webview.dart index e47c1e09..d67f1bf0 100755 --- a/lib/src/in_app_webview.dart +++ b/lib/src/in_app_webview.dart @@ -383,7 +383,7 @@ class _InAppWebViewState extends State { gestureRecognizers: widget.gestureRecognizers, layoutDirection: TextDirection.rtl, creationParams: { - 'initialUrl': Uri.parse(widget.initialUrl), + 'initialUrl': '${Uri.parse(widget.initialUrl)}', 'initialFile': widget.initialFile, 'initialData': widget.initialData?.toMap(), 'initialHeaders': widget.initialHeaders, @@ -416,7 +416,7 @@ class _InAppWebViewState extends State { onPlatformViewCreated: _onPlatformViewCreated, gestureRecognizers: widget.gestureRecognizers, creationParams: { - 'initialUrl': Uri.parse(widget.initialUrl), + 'initialUrl': '${Uri.parse(widget.initialUrl)}', 'initialFile': widget.initialFile, 'initialData': widget.initialData?.toMap(), 'initialHeaders': widget.initialHeaders,