mirror of
https://github.com/asjqkkkk/flutter-todos.git
synced 2025-08-06 14:19:24 +08:00
55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class LoadingWidget extends StatefulWidget {
|
|
final Widget child;
|
|
|
|
const LoadingWidget({Key key, @required this.child}) : super(key: key);
|
|
|
|
@override
|
|
_LoadingWidgetState createState() => _LoadingWidgetState();
|
|
}
|
|
|
|
class _LoadingWidgetState extends State<LoadingWidget>
|
|
with SingleTickerProviderStateMixin {
|
|
AnimationController _controller;
|
|
Animation animation;
|
|
|
|
@override
|
|
void initState() {
|
|
_controller =
|
|
AnimationController(vsync: this, duration: Duration(seconds: 10));
|
|
animation = Tween(begin: 0.0, end: 1.0).animate(
|
|
CurvedAnimation(parent: _controller, curve: Curves.ease));
|
|
_controller.addStatusListener((status) {
|
|
if (status == AnimationStatus.completed) {
|
|
_controller.reset();
|
|
_controller.forward();
|
|
}
|
|
});
|
|
_controller.forward();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedBuilder(
|
|
animation: animation,
|
|
builder: (ctx, child) {
|
|
return Transform.scale(
|
|
scale: ((animation.value - 0.5) * 2).abs(),
|
|
child: child,
|
|
);
|
|
},
|
|
child: widget.child,
|
|
);
|
|
}
|
|
}
|