Skip to content

Commit

Permalink
<fix> board: try to fix disappearing chips
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed Apr 23, 2021
1 parent 50d77e9 commit 466ce51
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/widgets/game/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class _BoardWidgetState extends State<BoardWidget>
static const num _ANIM_DURATION_MULTIPLIER_NORMAL = 1.0;
static const num _ANIM_DURATION_MULTIPLIER_SPEED_RUN = 0.6;

static const int _ANIM_DURATION_BLINK_HALF = 200;
static const int _ANIM_DURATION_BLINK_HALF = 100;
static const int _ANIM_DURATION_MOVE = 200;
static const int _ANIM_DURATION_COLOR_BACKGROUND = 200;

Expand Down Expand Up @@ -225,24 +225,26 @@ class _BoardWidgetState extends State<BoardWidget>
);
}

extra.identity = chip.identity;

// Animate the color change!
if (chip.score > 0) {
final color = _getColorFor(score: chip.score);
final wasIdentity = extra.identity;
if (wasIdentity != chip.identity) {
if (extra.backgroundColor != color)
if (extra.backgroundColor != color) {
_disposeAnimation(chip, _ANIM_COLOR_BACKGROUND_TAG);
setState(() {
extra.backgroundColor = color;
});
}
} else {
_startColorBackgroundAnimation(chip,
from: extra.backgroundColor, to: color);
}
}
final opacity = _getOpacityFor(score: chip.score);
_startOpacityAnimation(chip, from: extra.opacity, to: opacity);

extra.identity = chip.identity;
}
}

Expand Down Expand Up @@ -299,6 +301,14 @@ class _BoardWidgetState extends State<BoardWidget>
}

void _startColorBackgroundAnimation(Chip chip, {Color from, Color to}) {
final target = chips[chip.number];
if (from == to) {
_disposeAnimation(chip, _ANIM_COLOR_BACKGROUND_TAG);
// just in case, if the actual background color differs.
target.backgroundColor = to;
return;
}

final duration = Duration(
milliseconds:
_applyAnimationMultiplier(_ANIM_DURATION_COLOR_BACKGROUND));
Expand All @@ -309,7 +319,6 @@ class _BoardWidgetState extends State<BoardWidget>
vsync: this,
);

final target = chips[chip.number];
final animation = CurvedAnimation(
parent: controller,
curve: curve,
Expand Down

0 comments on commit 466ce51

Please sign in to comment.