Skip to content

Commit

Permalink
Merge pull request #262 from AlexVincent525/fix-crash-on-nil-or-inval…
Browse files Browse the repository at this point in the history
…id-url

Fix crash on nil/invalid URL (iOS)
  • Loading branch information
pichillilorenzo authored May 9, 2020
2 parents 001c95e + 86b0596 commit 0f358f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions ios/Classes/FlutterWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/in_app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class _InAppWebViewState extends State<InAppWebView> {
gestureRecognizers: widget.gestureRecognizers,
layoutDirection: TextDirection.rtl,
creationParams: <String, dynamic>{
'initialUrl': widget.initialUrl,
'initialUrl': '${Uri.parse(widget.initialUrl)}',
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
'initialHeaders': widget.initialHeaders,
Expand Down Expand Up @@ -416,7 +416,7 @@ class _InAppWebViewState extends State<InAppWebView> {
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
creationParams: <String, dynamic>{
'initialUrl': widget.initialUrl,
'initialUrl': '${Uri.parse(widget.initialUrl)}',
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
'initialHeaders': widget.initialHeaders,
Expand Down

0 comments on commit 0f358f0

Please sign in to comment.