@@ -21,7 +21,8 @@ abstract class WebViewPlatformCallbacksHandler {
21
21
/// Invoked by [WebViewPlatformController] when a navigation request is pending.
22
22
///
23
23
/// If true is returned the navigation is allowed, otherwise it is blocked.
24
- FutureOr <bool > onNavigationRequest ({String url, bool isForMainFrame});
24
+ FutureOr <bool > onNavigationRequest (
25
+ {required String url, required bool isForMainFrame});
25
26
26
27
/// Invoked by [WebViewPlatformController] when a page has started loading.
27
28
void onPageStarted (String url);
@@ -103,8 +104,8 @@ class WebResourceError {
103
104
/// A user should not need to instantiate this class, but will receive one in
104
105
/// [WebResourceErrorCallback] .
105
106
WebResourceError ({
106
- @ required this .errorCode,
107
- @ required this .description,
107
+ required this .errorCode,
108
+ required this .description,
108
109
this .domain,
109
110
this .errorType,
110
111
this .failingUrl,
@@ -131,21 +132,21 @@ class WebResourceError {
131
132
/// in Objective-C. See
132
133
/// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html
133
134
/// for more information on error handling on iOS.
134
- final String domain;
135
+ final String ? domain;
135
136
136
137
/// Description of the error that can be used to communicate the problem to the user.
137
138
final String description;
138
139
139
140
/// The type this error can be categorized as.
140
141
///
141
142
/// This will never be `null` on Android, but can be `null` on iOS.
142
- final WebResourceErrorType errorType;
143
+ final WebResourceErrorType ? errorType;
143
144
144
145
/// Gets the URL for which the resource request was made.
145
146
///
146
147
/// This value is not provided on iOS. Alternatively, you can keep track of
147
148
/// the last values provided to [WebViewPlatformController.loadUrl] .
148
- final String failingUrl;
149
+ final String ? failingUrl;
149
150
}
150
151
151
152
/// Interface for talking to the webview's platform implementation.
@@ -176,7 +177,7 @@ abstract class WebViewPlatformController {
176
177
/// Throws an ArgumentError if `url` is not a valid URL string.
177
178
Future <void > loadUrl (
178
179
String url,
179
- Map <String , String > headers,
180
+ Map <String , String >? headers,
180
181
) {
181
182
throw UnimplementedError (
182
183
"WebView loadUrl is not implemented on the current platform" );
@@ -194,7 +195,7 @@ abstract class WebViewPlatformController {
194
195
/// Accessor to the current URL that the WebView is displaying.
195
196
///
196
197
/// If no URL was ever loaded, returns `null` .
197
- Future <String > currentUrl () {
198
+ Future <String ? > currentUrl () {
198
199
throw UnimplementedError (
199
200
"WebView currentUrl is not implemented on the current platform" );
200
201
}
@@ -281,7 +282,7 @@ abstract class WebViewPlatformController {
281
282
}
282
283
283
284
/// Returns the title of the currently loaded page.
284
- Future <String > getTitle () {
285
+ Future <String ? > getTitle () {
285
286
throw UnimplementedError (
286
287
"WebView getTitle is not implemented on the current platform" );
287
288
}
@@ -337,7 +338,7 @@ class WebSetting<T> {
337
338
: _value = value,
338
339
isPresent = true ;
339
340
340
- final T _value;
341
+ final T ? _value;
341
342
342
343
/// The setting's value.
343
344
///
@@ -347,7 +348,14 @@ class WebSetting<T> {
347
348
throw StateError ('Cannot access a value of an absent WebSetting' );
348
349
}
349
350
assert (isPresent);
350
- return _value;
351
+ // The intention of this getter is to return T whether it is nullable or
352
+ // not whereas _value is of type T? since _value can be null even when
353
+ // T is not nullable (when isPresent == false).
354
+ //
355
+ // We promote _value to T using `as T` instead of `!` operator to handle
356
+ // the case when _value is legitimately null (and T is a nullable type).
357
+ // `!` operator would always throw if _value is null.
358
+ return _value as T ;
351
359
}
352
360
353
361
/// True when this web setting instance contains a value.
@@ -358,7 +366,7 @@ class WebSetting<T> {
358
366
@override
359
367
bool operator == (Object other) {
360
368
if (other.runtimeType != runtimeType) return false ;
361
- final WebSetting <T > typedOther = other;
369
+ final WebSetting <T > typedOther = other as WebSetting < T > ;
362
370
return typedOther.isPresent == isPresent && typedOther._value == _value;
363
371
}
364
372
@@ -382,19 +390,19 @@ class WebSettings {
382
390
this .hasNavigationDelegate,
383
391
this .debuggingEnabled,
384
392
this .gestureNavigationEnabled,
385
- @ required this .userAgent,
393
+ required this .userAgent,
386
394
}) : assert (userAgent != null );
387
395
388
396
/// The JavaScript execution mode to be used by the webview.
389
- final JavascriptMode javascriptMode;
397
+ final JavascriptMode ? javascriptMode;
390
398
391
399
/// Whether the [WebView] has a [NavigationDelegate] set.
392
- final bool hasNavigationDelegate;
400
+ final bool ? hasNavigationDelegate;
393
401
394
402
/// Whether to enable the platform's webview content debugging tools.
395
403
///
396
404
/// See also: [WebView.debuggingEnabled] .
397
- final bool debuggingEnabled;
405
+ final bool ? debuggingEnabled;
398
406
399
407
/// The value used for the HTTP `User-Agent:` request header.
400
408
///
@@ -404,12 +412,12 @@ class WebSettings {
404
412
/// last time it was set.
405
413
///
406
414
/// See also [WebView.userAgent] .
407
- final WebSetting <String > userAgent;
415
+ final WebSetting <String ? > userAgent;
408
416
409
417
/// Whether to allow swipe based navigation in iOS.
410
418
///
411
419
/// See also: [WebView.gestureNavigationEnabled]
412
- final bool gestureNavigationEnabled;
420
+ final bool ? gestureNavigationEnabled;
413
421
414
422
@override
415
423
String toString () {
@@ -428,7 +436,7 @@ class CreationParams {
428
436
CreationParams ({
429
437
this .initialUrl,
430
438
this .webSettings,
431
- this .javascriptChannelNames,
439
+ this .javascriptChannelNames = const < String > {} ,
432
440
this .userAgent,
433
441
this .autoMediaPlaybackPolicy =
434
442
AutoMediaPlaybackPolicy .require_user_action_for_all_media_types,
@@ -437,12 +445,12 @@ class CreationParams {
437
445
/// The initialUrl to load in the webview.
438
446
///
439
447
/// When null the webview will be created without loading any page.
440
- final String initialUrl;
448
+ final String ? initialUrl;
441
449
442
450
/// The initial [WebSettings] for the new webview.
443
451
///
444
452
/// This can later be updated with [WebViewPlatformController.updateSettings] .
445
- final WebSettings webSettings;
453
+ final WebSettings ? webSettings;
446
454
447
455
/// The initial set of JavaScript channels that are configured for this webview.
448
456
///
@@ -460,7 +468,7 @@ class CreationParams {
460
468
/// The value used for the HTTP User-Agent: request header.
461
469
///
462
470
/// When null the platform's webview default is used for the User-Agent header.
463
- final String userAgent;
471
+ final String ? userAgent;
464
472
465
473
/// Which restrictions apply on automatic media playback.
466
474
final AutoMediaPlaybackPolicy autoMediaPlaybackPolicy;
@@ -475,7 +483,7 @@ class CreationParams {
475
483
///
476
484
/// See also the `onWebViewPlatformCreated` argument for [WebViewPlatform.build] .
477
485
typedef WebViewPlatformCreatedCallback = void Function (
478
- WebViewPlatformController webViewPlatformController);
486
+ WebViewPlatformController ? webViewPlatformController);
479
487
480
488
/// Interface for a platform implementation of a WebView.
481
489
///
@@ -505,14 +513,14 @@ abstract class WebViewPlatform {
505
513
///
506
514
/// `webViewPlatformHandler` must not be null.
507
515
Widget build ({
508
- BuildContext context,
516
+ required BuildContext context,
509
517
// TODO(amirh): convert this to be the actual parameters.
510
518
// I'm starting without it as the PR is starting to become pretty big.
511
519
// I'll followup with the conversion PR.
512
- CreationParams creationParams,
513
- @ required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler,
514
- WebViewPlatformCreatedCallback onWebViewPlatformCreated,
515
- Set <Factory <OneSequenceGestureRecognizer >> gestureRecognizers,
520
+ required CreationParams creationParams,
521
+ required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler,
522
+ WebViewPlatformCreatedCallback ? onWebViewPlatformCreated,
523
+ Set <Factory <OneSequenceGestureRecognizer >>? gestureRecognizers,
516
524
});
517
525
518
526
/// Clears all cookies for all [WebView] instances.
0 commit comments