Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/badge_animation/ani_fixed.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:math';
import 'package:badgemagic/badge_animation/animation_abstract.dart';

class FixedAnimation extends BadgeAnimation {
@override
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
List<List<bool>> processGrid, List<List<bool>> canvas) {
int newWidth = processGrid[0].length;
int horizontalOffset = (badgeWidth - newWidth) ~/ 2;
int horizontalOffset = max(0, (badgeWidth - newWidth) ~/ 2);

for (int i = 0; i < badgeHeight; i++) {
for (int j = 0; j < badgeWidth; j++) {
Expand Down
6 changes: 6 additions & 0 deletions lib/badge_animation/animation_abstract.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
abstract class BadgeAnimation {
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
List<List<bool>> processGrid, List<List<bool>> canvas);

@override
bool operator ==(Object other) => runtimeType == other.runtimeType;

@override
int get hashCode => runtimeType.hashCode;
}
6 changes: 4 additions & 2 deletions lib/providers/animation_badge_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,11 @@ class AnimationBadgeProvider extends ChangeNotifier {
int? getAnimationIndex() {
for (var animation in animationMap.entries) {
if (animation.value != null && animation.value == _currentAnimation) {
logger.i("Animation Index: ${animation.key}");
return animation.key;
}
}
return 0;
return null;
Comment on lines +221 to +225

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Changing the default animation index from 0 to null may break existing callers if they assume a non-null value.

getAnimationIndex() used to always return 0 when no animation matched; now it can return null. Call sites may currently rely on 0 as a sentinel or use the value without null checks. Please review existing usages to ensure they handle null correctly, or define and document a clear convention for when null vs 0 should be used to avoid regressions.

}

bool isAnimationActive(BadgeAnimation? badgeAnimation) {
Expand All @@ -233,7 +234,8 @@ class AnimationBadgeProvider extends ChangeNotifier {
String message, Converters converters, bool isInverted) async {
bool isSpecial = isSpecialAnimationSelected();
if (message.isEmpty && !isSpecial) {
stopAllAnimations();
_timer?.cancel();
_animationIndex = 0;
List<List<bool>> emptyGrid =
List.generate(11, (i) => List.generate(44, (j) => false));
_newGrid = emptyGrid;
Expand Down
Loading