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

Commit d5cf9f9

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

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

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

+5-5
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

-2
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

+20-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ - (void)onLoadFile:(FlutterMethodCall*)call result:(FlutterResult)result {
206206
}
207207

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.",
213+
[call arguments]];
214+
result([FlutterError errorWithCode:@"loadFile_failed"
215+
message:@"Failed parsing file path."
216+
details:errorDetails]);
217+
return;
218+
}
219+
209220
NSURL* baseUrl = [url URLByDeletingLastPathComponent];
210221

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

215226
- (void)onLoadHtmlString:(FlutterMethodCall*)call result:(FlutterResult)result {
216227
NSDictionary* arguments = [call arguments];
217-
if (!arguments || ![arguments isKindOfClass:NSDictionary.class]) {
228+
if (![arguments isKindOfClass:NSDictionary.class]) {
218229
result([FlutterError
219230
errorWithCode:@"loadHtmlString_failed"
220231
message:@"Failed parsing arguments."
@@ -603,6 +614,14 @@ - (void)updateUserAgent:(NSString*)userAgent {
603614
}
604615
}
605616

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

0 commit comments

Comments
 (0)