@@ -16,8 +16,21 @@ class Badge extends StatefulWidget {
1616 this .ignorePointer = false ,
1717 this .stackFit = StackFit .loose,
1818 this .onTap,
19+ this .animationController,
20+ this .appearanceController,
1921 }) : super (key: key);
2022
23+ /// Controls badge animation. By default it is created automatically
24+ /// but you can pass your own [AnimationController] to have better control
25+ /// over badge animation.
26+ final AnimationController ? animationController;
27+
28+ /// Controls badge appearance and disappearance animation.
29+ /// By default it is created automatically
30+ /// but you can pass your own [AnimationController] to have better control
31+ /// over badge animation.
32+ final AnimationController ? appearanceController;
33+
2134 /// The badge child, e.g. cart icon button.
2235 final Widget ? child;
2336
@@ -68,16 +81,19 @@ class BadgeState extends State<Badge> with TickerProviderStateMixin {
6881 super .initState ();
6982 enableLoopAnimation =
7083 widget.badgeAnimation.animationDuration.inMilliseconds > 0 ;
71- _animationController = AnimationController (
72- duration: widget.badgeAnimation.animationDuration,
73- reverseDuration: widget.badgeAnimation.animationDuration,
74- vsync: this ,
75- );
76- _appearanceController = AnimationController (
77- duration: widget.badgeAnimation.disappearanceFadeAnimationDuration,
78- reverseDuration: widget.badgeAnimation.disappearanceFadeAnimationDuration,
79- vsync: this ,
80- );
84+ _animationController = widget.animationController ??
85+ AnimationController (
86+ duration: widget.badgeAnimation.animationDuration,
87+ reverseDuration: widget.badgeAnimation.animationDuration,
88+ vsync: this ,
89+ );
90+ _appearanceController = widget.animationController ??
91+ AnimationController (
92+ duration: widget.badgeAnimation.disappearanceFadeAnimationDuration,
93+ reverseDuration:
94+ widget.badgeAnimation.disappearanceFadeAnimationDuration,
95+ vsync: this ,
96+ );
8197
8298 _animation = CurvedAnimation (
8399 parent: _animationController,
0 commit comments