Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit f78a3bc

Browse files
committed
Apply feedback on PR
1 parent 5218c0a commit f78a3bc

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/webview_flutter/webview_flutter_wkwebview/example/lib/main.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ const String kLocalFileExamplePage = '''
4646
<body>
4747
4848
<h1>Local demo page</h1>
49-
<p>This is an example page used to demonstrate how to load a local file or HTML string using the <a href="https://pub.dev/packages/webview_flutter">Flutter webview</a> plugin.</p>
49+
<p>
50+
This is an example page used to demonstrate how to load a local file or HTML
51+
string using the <a href="https://pub.dev/packages/webview_flutter">Flutter
52+
webview</a> plugin.
53+
</p>
5054
5155
</body>
5256
</html>
@@ -343,10 +347,6 @@ class _SampleMenu extends StatelessWidget {
343347
final String tmpDir = (await getTemporaryDirectory()).path;
344348
File indexFile = File('$tmpDir/www/index.html');
345349

346-
if (await indexFile.exists()) {
347-
return indexFile.path;
348-
}
349-
350350
await Directory('$tmpDir/www').create(recursive: true);
351351
await indexFile.writeAsString(kLocalFileExamplePage);
352352

packages/webview_flutter/webview_flutter_wkwebview/example/lib/web_view.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ class WebViewController {
315315
Future<void> loadFile(
316316
String absoluteFilePath,
317317
) {
318-
assert(absoluteFilePath != null || absoluteFilePath.isNotEmpty);
319318
return _webViewPlatformController.loadFile(absoluteFilePath);
320319
}
321320

@@ -327,7 +326,6 @@ class WebViewController {
327326
String html, {
328327
String? baseUrl,
329328
}) {
330-
assert(html != null || html.isNotEmpty);
331329
return _webViewPlatformController.loadHtmlString(
332330
html,
333331
baseUrl: baseUrl,

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FlutterWebView.m

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,18 @@ - (void)onLoadFile:(FlutterMethodCall*)call result:(FlutterResult)result {
204204
details:error]);
205205
return;
206206
}
207-
207+
208208
NSURL* url = [NSURL fileURLWithPath:[call arguments] isDirectory:NO];
209+
210+
if (!url) {
211+
NSString *errorDetails = [NSString stringWithFormat:@"Initializing NSURL with the supplied "
212+
@"'%@' path resulted in a nil value.", [call arguments]];
213+
result([FlutterError errorWithCode:@"loadFile_failed"
214+
message:@"Failed parsing file path."
215+
details:errorDetails]);
216+
return;
217+
}
218+
209219
NSURL* baseUrl = [url URLByDeletingLastPathComponent];
210220

211221
[_webView loadFileURL:url allowingReadAccessToURL:baseUrl];
@@ -214,7 +224,7 @@ - (void)onLoadFile:(FlutterMethodCall*)call result:(FlutterResult)result {
214224

215225
- (void)onLoadHtmlString:(FlutterMethodCall*)call result:(FlutterResult)result {
216226
NSDictionary* arguments = [call arguments];
217-
if (!arguments || ![arguments isKindOfClass:NSDictionary.class]) {
227+
if (![arguments isKindOfClass:NSDictionary.class]) {
218228
result([FlutterError
219229
errorWithCode:@"loadHtmlString_failed"
220230
message:@"Failed parsing arguments."
@@ -603,6 +613,13 @@ - (void)updateUserAgent:(NSString*)userAgent {
603613
}
604614
}
605615

616+
/**
617+
* Validates if the given `argument` is a non-null non-empty string.
618+
*
619+
* @param argument The argument that should be validated.
620+
* @param errorDetails An optional NSString variable which will contain a detailed error message in case the supplied argument is not valid.
621+
* @return `true` if the given `argument` is a valid non-null, non-empty string; otherwise `false`.
622+
*/
606623
+ (bool)isValidStringArgument:(id)argument withErrorMessage:(NSString**)errorDetails {
607624
if (!argument) {
608625
if (errorDetails) {

0 commit comments

Comments
 (0)