Skip to content

Commit

Permalink
add: new onLoading parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
LeGoffMael committed Dec 21, 2022
1 parent 7ea153c commit 6465bbc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/src/crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Crop extends StatefulWidget {
/// Specifies [placeholderWidget] to display a [Widget] while the image is loading
final Widget? placeholderWidget;

/// Function called when the image or the view is recomputed
final Function(bool isReady)? onLoading;

const Crop({
Key? key,
required this.image,
Expand All @@ -32,6 +35,7 @@ class Crop extends StatefulWidget {
this.alwaysShowGrid = false,
this.onImageError,
this.placeholderWidget,
this.onLoading,
}) : super(key: key);

Crop.file(
Expand All @@ -43,6 +47,7 @@ class Crop extends StatefulWidget {
this.alwaysShowGrid = false,
this.onImageError,
this.placeholderWidget,
this.onLoading,
}) : image = FileImage(file, scale: scale),
super(key: key);

Expand All @@ -56,6 +61,7 @@ class Crop extends StatefulWidget {
this.alwaysShowGrid = false,
this.onImageError,
this.placeholderWidget,
this.onLoading,
}) : image = AssetImage(assetName, bundle: bundle, package: package),
super(key: key);

Expand Down Expand Up @@ -143,6 +149,7 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
super.didUpdateWidget(oldWidget);

if (widget.image != oldWidget.image) {
_onLoading(false);
_image = null;
_getImage();
} else if (widget.aspectRatio != oldWidget.aspectRatio) {
Expand All @@ -162,6 +169,12 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
}
}

void _onLoading(bool isLoading) {
if (widget.onLoading != null) {
widget.onLoading!(isLoading);
}
}

void _getImage() {
widget.image.evict();
final oldImageStream = _imageStream;
Expand Down Expand Up @@ -335,6 +348,7 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
viewWidth,
viewHeight,
);
_onLoading(true);
});
});

Expand Down

0 comments on commit 6465bbc

Please sign in to comment.