69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:novyronst/root/lib_export.dart';
|
|
|
|
class NyLoadingWidget extends StatefulWidget {
|
|
final double size;
|
|
|
|
const NyLoadingWidget({
|
|
super.key,
|
|
this.size = 10,
|
|
});
|
|
|
|
@override
|
|
State<NyLoadingWidget> createState() => _ThreeDotLoadingState();
|
|
}
|
|
|
|
class _ThreeDotLoadingState extends State<NyLoadingWidget>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
int _currentIndex = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 600),
|
|
)..addListener(() {
|
|
// 每完成一次动画循环,更新索引
|
|
if (_controller.isCompleted) {
|
|
_controller.reset();
|
|
setState(() {
|
|
_currentIndex = (_currentIndex + 1) % 3;
|
|
});
|
|
_controller.forward();
|
|
}
|
|
});
|
|
_controller.forward();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: AppScreen.screenWidth,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: List.generate(3, (index) {
|
|
final isDark = index == _currentIndex;
|
|
return AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
margin: const EdgeInsets.symmetric(horizontal: 6),
|
|
width: widget.size,
|
|
height: widget.size,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: isDark ? ConstColor.withValue('#89F011') : ConstColor.withValue('#E2FFC0'),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
} |