@@ -29,7 +29,6 @@ class TDIconLabel extends Icon implements TDLabelWidget {
2929
3030/// 进度条组件
3131class TDProgress extends StatelessWidget {
32-
3332 /// 进度条类型
3433 final TDProgressType type;
3534
@@ -72,7 +71,7 @@ class TDProgress extends StatelessWidget {
7271 const TDProgress ({
7372 Key ? key,
7473 required this .type,
75- this . value,
74+ double ? value,
7675 this .label,
7776 this .progressStatus = TDProgressStatus .primary,
7877 this .progressLabelPosition = TDProgressLabelPosition .inside,
@@ -84,7 +83,9 @@ class TDProgress extends StatelessWidget {
8483 this .showLabel = true ,
8584 this .onTap,
8685 this .onLongPress,
87- }) : super (key: key);
86+ }) : value =
87+ (value == null ) ? null : (value < 0 ? 0 : (value > 1 ? 1 : value)),
88+ super (key: key);
8889
8990 @override
9091 Widget build (BuildContext context) {
@@ -203,11 +204,11 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
203204 super .initState ();
204205 _animationController = AnimationController (
205206 vsync: this ,
206- duration: const Duration (seconds: 1 ),
207+ duration: Duration (
208+ milliseconds:
209+ widget.value != null ? (widget.value! * 1000 ).toInt () : 1000 ),
207210 );
208211 _updateAnimation ();
209- final int duration = (_animation.value * 1000 ).toInt ();
210- _animationController.duration = Duration (milliseconds: duration);
211212 _updateEffectiveColor ();
212213 _updateEffectiveLabel ();
213214 }
@@ -263,8 +264,12 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
263264 final bool showIconBorder = widget.type == TDProgressType .linear;
264265
265266 Widget getAutoText () => showAutoText && widget.type != TDProgressType .micro
266- ? Text ('${(widget .value ! * 100 ).round ()}%' )
267- : const Text ("" );
267+ ? AnimatedBuilder (
268+ animation: _animation,
269+ builder: (context, child) {
270+ return Text ('${(_animation .value * 100 ).round ()}%' );
271+ })
272+ : const Text ('' );
268273
269274 final statusWidgets = {
270275 TDProgressStatus .primary: getAutoText (),
@@ -358,7 +363,7 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
358363 return Stack (
359364 children: [
360365 _buildBackgroundContainer (),
361- if (widget .value! > 0.1 )
366+ if (_animation .value > 0.1 )
362367 _buildProgressContainerWithLabel (progressWidth)
363368 else
364369 _buildProgressContainerWithLabelOutside (progressWidth),
@@ -536,7 +541,8 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
536541 alignment: Alignment .center,
537542 children: [
538543 _buildMicroOutline (),
539- if (widget.showLabel) _buildLabelWidget (TDTheme .of ().fontGyColor1),
544+ if (widget.showLabel)
545+ _buildLabelWidget (TDTheme .of ().fontGyColor1),
540546 ],
541547 ));
542548 });
0 commit comments