85 lines
2.0 KiB
Dart
85 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:gap/gap.dart';
|
|
|
|
class LoadingIndicator extends StatefulWidget {
|
|
final bool isActive;
|
|
|
|
const LoadingIndicator({super.key, this.isActive = true});
|
|
|
|
@override
|
|
State<LoadingIndicator> createState() => _LoadingIndicatorState();
|
|
}
|
|
|
|
class _LoadingIndicatorState extends State<LoadingIndicator>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
late Animation<double> _animation;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_controller = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 300),
|
|
);
|
|
|
|
_animation = CurvedAnimation(
|
|
parent: _controller,
|
|
curve: Curves.easeInOut,
|
|
);
|
|
|
|
if (widget.isActive) {
|
|
_controller.forward();
|
|
} else {
|
|
_controller.reverse();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant LoadingIndicator oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
|
|
if (widget.isActive != oldWidget.isActive) {
|
|
if (widget.isActive) {
|
|
_controller.forward();
|
|
} else {
|
|
_controller.reverse();
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizeTransition(
|
|
sizeFactor: _animation,
|
|
axisAlignment: -1, // Align animation from the top
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
|
|
color:
|
|
Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(
|
|
height: 16,
|
|
width: 16,
|
|
child: CircularProgressIndicator(strokeWidth: 2.5),
|
|
),
|
|
const Gap(8),
|
|
Text('loading'.tr),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|