Skip to content

Commit

Permalink
Clean up for pubdev
Browse files Browse the repository at this point in the history
  • Loading branch information
gskinner committed Mar 23, 2022
1 parent 2acabc2 commit b7b0b31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions lib/image_fade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ class _ImageResolver {
ImageInfo? _imageInfo;

_ImageResolver(ImageProvider provider, BuildContext context,
{this.onComplete, this.onError, this.onProgress, double? width, double? height}) {
{this.onComplete,
this.onError,
this.onProgress,
double? width,
double? height}) {
Size? size = width != null && height != null ? Size(width, height) : null;
ImageConfiguration config = createLocalImageConfiguration(context, size: size);
_listener = ImageStreamListener(_handleComplete, onChunk: _handleProgress, onError: _handleError);
ImageConfiguration config =
createLocalImageConfiguration(context, size: size);
_listener = ImageStreamListener(_handleComplete,
onChunk: _handleProgress, onError: _handleError);
_stream = provider.resolve(config);
_stream.addListener(_listener); // Called sync if already completed.
}
Expand Down Expand Up @@ -175,7 +181,8 @@ class _ImageFadeState extends State<ImageFade> with TickerProviderStateMixin {
@override
void didChangeDependencies() {
super.didChangeDependencies();
_update(context); // Can't call this in initState because createLocalImageConfiguration throws errors.
_update(
context); // Can't call this in initState because createLocalImageConfiguration throws errors.
}

@override
Expand Down Expand Up @@ -218,14 +225,16 @@ class _ImageFadeState extends State<ImageFade> with TickerProviderStateMixin {
}

void _handleComplete(_ImageResolver resolver) {
_front =
resolver.success ? _getImage(resolver.image) : widget.errorBuilder?.call(context, _front, resolver.exception);
_front = resolver.success
? _getImage(resolver.image)
: widget.errorBuilder?.call(context, _front, resolver.exception);
_buildTransition();
}

void _buildTransition() {
bool out = _front == null;
_controller.duration = widget.fadeDuration * (out ? 1 : 3 / 2); // Fade in for fadeDuration, out for 1/2 as long.
_controller.duration = widget.fadeDuration *
(out ? 1 : 3 / 2); // Fade in for fadeDuration, out for 1/2 as long.
_fadeFront = _front == null
? null
: FadeTransition(
Expand Down Expand Up @@ -265,7 +274,10 @@ class _ImageFadeState extends State<ImageFade> with TickerProviderStateMixin {
List<Widget> kids = [];

Widget? front = _fadeFront, back = _fadeBack;
if (_resolver != null && _resolver!.inLoad && widget.loadingBuilder != null && _front != null) {
if (_resolver != null &&
_resolver!.inLoad &&
widget.loadingBuilder != null &&
_front != null) {
front = widget.loadingBuilder!(context, _front!, _resolver!.chunkEvent);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 0.3.0

environment:
sdk: ">=2.13.4 <3.0.0"
flutter: ^2.2.3
flutter: '>=2.2.3'

dependencies:
flutter:
Expand Down

0 comments on commit b7b0b31

Please sign in to comment.