@@ -2,7 +2,7 @@ import 'package:badges/badges.dart';
2
2
import 'package:badges/src/badge_border_gradient.dart' ;
3
3
import 'package:badges/src/utils/calculation_utils.dart' ;
4
4
import 'package:badges/src/utils/drawing_utils.dart' ;
5
- import 'package:flutter/material.dart' ;
5
+ import 'package:flutter/material.dart' hide Badge ;
6
6
7
7
class Badge extends StatefulWidget {
8
8
const Badge ({
@@ -16,8 +16,21 @@ class Badge extends StatefulWidget {
16
16
this .ignorePointer = false ,
17
17
this .stackFit = StackFit .loose,
18
18
this .onTap,
19
+ this .animationController,
20
+ this .appearanceController,
19
21
}) : super (key: key);
20
22
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
+
21
34
/// The badge child, e.g. cart icon button.
22
35
final Widget ? child;
23
36
@@ -68,16 +81,19 @@ class BadgeState extends State<Badge> with TickerProviderStateMixin {
68
81
super .initState ();
69
82
enableLoopAnimation =
70
83
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
+ );
81
97
82
98
_animation = CurvedAnimation (
83
99
parent: _animationController,
0 commit comments