Skip to content

Commit

Permalink
Fix for issue #79 — scales with 0 value
Browse files Browse the repository at this point in the history
  • Loading branch information
gskinner committed Nov 19, 2023
1 parent 8845fcd commit 31709e9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/src/effects/scale_effect.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' as math;

import 'package:flutter/widgets.dart';

import '../../flutter_animate.dart';
Expand All @@ -11,7 +13,8 @@ class ScaleEffect extends Effect<Offset> {
static const Offset defaultValue = Offset(defaultScale, defaultScale);

static const double neutralScale = 1.0;
static const double defaultScale = 0.0;
static const double defaultScale = 0;
static const double minScale = 0.000001;

const ScaleEffect({
Duration? delay,
Expand Down Expand Up @@ -42,14 +45,20 @@ class ScaleEffect extends Effect<Offset> {
animation: animation,
builder: (_, __) {
return Transform.scale(
scaleX: animation.value.dx,
scaleY: animation.value.dy,
scaleX: _normalizeScale(animation.value.dx),
scaleY: _normalizeScale(animation.value.dy),
alignment: alignment ?? Alignment.center,
child: child,
);
},
);
}

double _normalizeScale(double scale) {
// addresses an issue with zero value scales:
// https://github.com/gskinner/flutter_animate/issues/79
return scale < minScale ? minScale : scale;
}
}

extension ScaleEffectExtensions<T> on AnimateManager<T> {
Expand Down

0 comments on commit 31709e9

Please sign in to comment.