Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Animate linear progress indicator of LinearProgressDialog

ashilkn60f94362d248
diff --git a/mobile/lib/ui/common/linear_progress_dialog.dart b/mobile/lib/ui/common/linear_progress_dialog.dart
index eee924220b..e28f79273e 100644
--- a/mobile/lib/ui/common/linear_progress_dialog.dart
+++ b/mobile/lib/ui/common/linear_progress_dialog.dart
@@ -11,19 +11,44 @@ class LinearProgressDialog extends StatefulWidget {
LinearProgressDialogState createState() => LinearProgressDialogState();
}
-class LinearProgressDialogState extends State<LinearProgressDialog> {
- double? _progress;
+class LinearProgressDialogState extends State<LinearProgressDialog>
+ with TickerProviderStateMixin {
+ late AnimationController controller;
+ late Tween<double> _tween;
+ late Animation<double> _animation;
+
+ double _target = 0.0;
@override
void initState() {
- _progress = 0;
super.initState();
+ controller = AnimationController(
+ vsync: this,
+ duration: const Duration(milliseconds: 300),
+ );
+
+ _tween = Tween<double>(begin: _target, end: _target);
+
+ _animation = _tween.animate(
+ CurvedAnimation(
+ curve: Curves.easeInOut,
+ parent: controller,
+ ),
+ );
+ }
+
+ @override
+ void dispose() {
+ controller.dispose();
+ super.dispose();
}
void setProgress(double progress) {
- setState(() {
- _progress = progress;
- });
+ _target = progress;
+ _tween.begin = _tween.end;
+ controller.reset();
+ _tween.end = progress;
+ controller.forward();
}
@override
@@ -36,11 +61,16 @@ class LinearProgressDialogState extends State<LinearProgressDialog> {
style: getEnteTextTheme(context).smallMuted,
textAlign: TextAlign.center,
),
- content: LinearProgressIndicator(
- value: _progress,
- valueColor: AlwaysStoppedAnimation<Color>(
- Theme.of(context).colorScheme.greenAlternative,
- ),
+ content: AnimatedBuilder(
+ animation: _animation,
+ builder: (context, child) {
+ return LinearProgressIndicator(
+ value: _animation.value,
+ valueColor: AlwaysStoppedAnimation<Color>(
+ Theme.of(context).colorScheme.greenAlternative,
+ ),
+ );
+ },
),
),
);