Skip to content

Commit 99f46ca

Browse files
committed
取消初始加载动画
1 parent 3082339 commit 99f46ca

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tdesign-component/lib/src/components/progress/td_progress.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class TDProgress extends StatelessWidget {
9090
@override
9191
Widget build(BuildContext context) {
9292
final defaultValues = _getDefaultValues(type);
93-
return _ProgressIndicator(
93+
return MyProgressIndicator(
9494
value: value,
9595
label: label,
9696
progressStatus: progressStatus,
@@ -156,7 +156,7 @@ class _DefaultValues {
156156
}
157157

158158
/// 构建工具类
159-
class _ProgressIndicator extends StatefulWidget {
159+
class MyProgressIndicator extends StatefulWidget {
160160
final double? value;
161161
final TDLabelWidget? label;
162162
final TDProgressLabelPosition progressLabelPosition;
@@ -171,7 +171,7 @@ class _ProgressIndicator extends StatefulWidget {
171171
final VoidCallback? onTap;
172172
final VoidCallback? onLongPress;
173173

174-
const _ProgressIndicator({
174+
const MyProgressIndicator({
175175
Key? key,
176176
this.value,
177177
this.label,
@@ -192,7 +192,7 @@ class _ProgressIndicator extends StatefulWidget {
192192
_ProgressIndicatorState createState() => _ProgressIndicatorState();
193193
}
194194

195-
class _ProgressIndicatorState extends State<_ProgressIndicator>
195+
class _ProgressIndicatorState extends State<MyProgressIndicator>
196196
with SingleTickerProviderStateMixin {
197197
late AnimationController _animationController;
198198
late Animation<double> _animation;
@@ -204,6 +204,7 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
204204
super.initState();
205205
_animationController = AnimationController(
206206
vsync: this,
207+
value: widget.value ?? 0,
207208
duration: Duration(
208209
milliseconds:
209210
widget.value != null ? (widget.value! * 1000).toInt() : 1000),
@@ -214,10 +215,10 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
214215
}
215216

216217
@override
217-
void didUpdateWidget(_ProgressIndicator oldWidget) {
218+
void didUpdateWidget(MyProgressIndicator oldWidget) {
218219
super.didUpdateWidget(oldWidget);
219220
if (oldWidget.value != widget.value) {
220-
_updateAnimation();
221+
_updateAnimation(oldWidgetValue: oldWidget.value);
221222
}
222223
if (oldWidget.color != widget.color ||
223224
oldWidget.progressStatus != widget.progressStatus) {
@@ -250,10 +251,10 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
250251
widget.label ?? _getDefaultLabelFromStatus(widget.progressStatus);
251252
}
252253

253-
void _updateAnimation() {
254-
_animation = Tween<double>(begin: 0, end: widget.value ?? 0)
254+
void _updateAnimation({double? oldWidgetValue}) {
255+
_animation = Tween<double>(begin: _animationController.value, end: widget.value ?? 0)
255256
.animate(_animationController);
256-
_animationController.forward(from: 0);
257+
_animationController.forward(from: _animationController.value);
257258
}
258259

259260
Widget _getDefaultLabelFromStatus(TDProgressStatus status) {
@@ -264,11 +265,7 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
264265
final bool showIconBorder = widget.type == TDProgressType.linear;
265266

266267
Widget getAutoText() => showAutoText && widget.type != TDProgressType.micro
267-
? AnimatedBuilder(
268-
animation: _animation,
269-
builder: (context, child) {
270-
return Text('${(_animation.value * 100).round()}%');
271-
})
268+
? Text('${(widget.value! * 100).round()}%')
272269
: const Text('');
273270

274271
final statusWidgets = {
@@ -363,7 +360,7 @@ class _ProgressIndicatorState extends State<_ProgressIndicator>
363360
return Stack(
364361
children: [
365362
_buildBackgroundContainer(),
366-
if (_animation.value > 0.1)
363+
if (widget.value! > 0.1)
367364
_buildProgressContainerWithLabel(progressWidth)
368365
else
369366
_buildProgressContainerWithLabelOutside(progressWidth),

0 commit comments

Comments
 (0)