import 'dart:math';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart';
class ShakeAnimation extends StatefulWidget {
@override
_ShakeAnimationState createState() => _ShakeAnimationState();
}
class _ShakeAnimationState extends State<ShakeAnimation>
with SingleTickerProviderStateMixin {
AnimationController animationController;
Animation<double> animation;
@override
void initState() {
super.initState();
animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 5),
)..addListener(() => setState(() {}));
animation = Tween<double>(
begin: 50.0,
end: 120.0,
).animate(animationController);
animationController.forward();
}
Vector3 _shake() {
double progress = animationController.value;
double offset = sin(progress * pi * 10.0);
return Vector3(offset * 4, 0.0, 0.0);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Shake animation example")),
body: Center(
child: Transform(
transform: Matrix4.translation(_shake()),
child: FlutterLogo(
size: 60.0,
),
),
),
);
}
}
'프로그래밍 > Flutter' 카테고리의 다른 글
Shared Preferences (1) | 2020.04.28 |
---|---|
Cupertino ActionSheet (0) | 2020.04.05 |
flutter_staggered_grid_view (0) | 2020.03.15 |
Flutter Search-bar 구현 (0) | 2020.03.13 |
플러터 - 크로스 플랫폼 (1) | 2020.03.11 |