@@ -142,6 +142,9 @@ typedef void PageStartedCallback(String url);
142142/// Signature for when a [WebView] has finished loading a page.
143143typedef void PageFinishedCallback (String url);
144144
145+ /// Signature for when a [WebView] is loading a page.
146+ typedef void PageLoadingCallback (int progress);
147+
145148/// Signature for when a [WebView] has failed to load a resource.
146149typedef void WebResourceErrorCallback (WebResourceError error);
147150
@@ -217,6 +220,7 @@ class WebView extends StatefulWidget {
217220 this .gestureRecognizers,
218221 this .onPageStarted,
219222 this .onPageFinished,
223+ this .onProgress,
220224 this .onWebResourceError,
221225 this .debuggingEnabled = false ,
222226 this .gestureNavigationEnabled = false ,
@@ -357,6 +361,9 @@ class WebView extends StatefulWidget {
357361 /// [WebViewController.evaluateJavascript] can assume this.
358362 final PageFinishedCallback ? onPageFinished;
359363
364+ /// Invoked when a page is loading.
365+ final PageLoadingCallback ? onProgress;
366+
360367 /// Invoked when a web resource has failed to load.
361368 ///
362369 /// This can be called for any resource (iframe, image, etc.), not just for
@@ -476,6 +483,7 @@ WebSettings _webSettingsFromWidget(WebView widget) {
476483 return WebSettings (
477484 javascriptMode: widget.javascriptMode,
478485 hasNavigationDelegate: widget.navigationDelegate != null ,
486+ hasProgressTracking: widget.onProgress != null ,
479487 debuggingEnabled: widget.debuggingEnabled,
480488 gestureNavigationEnabled: widget.gestureNavigationEnabled,
481489 allowsInlineMediaPlayback: widget.allowsInlineMediaPlayback,
@@ -488,6 +496,7 @@ WebSettings _clearUnchangedWebSettings(
488496 WebSettings currentValue, WebSettings newValue) {
489497 assert (currentValue.javascriptMode != null );
490498 assert (currentValue.hasNavigationDelegate != null );
499+ assert (currentValue.hasProgressTracking != null );
491500 assert (currentValue.debuggingEnabled != null );
492501 assert (currentValue.userAgent != null );
493502 assert (newValue.javascriptMode != null );
@@ -497,6 +506,7 @@ WebSettings _clearUnchangedWebSettings(
497506
498507 JavascriptMode ? javascriptMode;
499508 bool ? hasNavigationDelegate;
509+ bool ? hasProgressTracking;
500510 bool ? debuggingEnabled;
501511 WebSetting <String ?> userAgent = WebSetting .absent ();
502512 if (currentValue.javascriptMode != newValue.javascriptMode) {
@@ -505,6 +515,9 @@ WebSettings _clearUnchangedWebSettings(
505515 if (currentValue.hasNavigationDelegate != newValue.hasNavigationDelegate) {
506516 hasNavigationDelegate = newValue.hasNavigationDelegate;
507517 }
518+ if (currentValue.hasProgressTracking != newValue.hasProgressTracking) {
519+ hasProgressTracking = newValue.hasProgressTracking;
520+ }
508521 if (currentValue.debuggingEnabled != newValue.debuggingEnabled) {
509522 debuggingEnabled = newValue.debuggingEnabled;
510523 }
@@ -515,6 +528,7 @@ WebSettings _clearUnchangedWebSettings(
515528 return WebSettings (
516529 javascriptMode: javascriptMode,
517530 hasNavigationDelegate: hasNavigationDelegate,
531+ hasProgressTracking: hasProgressTracking,
518532 debuggingEnabled: debuggingEnabled,
519533 userAgent: userAgent,
520534 );
@@ -571,6 +585,12 @@ class _PlatformCallbacksHandler implements WebViewPlatformCallbacksHandler {
571585 }
572586
573587 @override
588+ void onProgress (int progress) {
589+ if (_widget.onProgress != null ) {
590+ _widget.onProgress !(progress);
591+ }
592+ }
593+
574594 void onWebResourceError (WebResourceError error) {
575595 if (_widget.onWebResourceError != null ) {
576596 _widget.onWebResourceError !(error);
0 commit comments