import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: positionedTransition(),
);
}
}
class positionedTransition extends StatefulWidget {
const positionedTransition({Key? key}) : super(key: key);
@override
_positionedTransitionState createState() => _positionedTransitionState();
}
class _positionedTransitionState extends State<positionedTransition>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
@override
void initState() {
// TODO: implement initState
// PositionedTransition의 컨트롤러를 컨트롤할 컨트롤러
_animationController =
AnimationController(vsync: this, duration: Duration(seconds: 5));
_animationController.repeat();
super.initState();
// 컨트롤러 초기화
;
}
@override
Widget build(BuildContext context) {
// 미디어쿼리로 디바이스 높이가져옴
double height = MediaQuery.of(context).size.height;
// PositionedTransition 컨트롤러 생성
Animation<RelativeRect> _controller = RelativeRectTween(
begin: RelativeRect.fromLTRB(0, height, 0, 0),
end: RelativeRect.fromLTRB(0, 0, 0, 0))
.animate(CurvedAnimation(
parent: _animationController, curve: Curves.easeInOut));
return Scaffold(
body: Stack(
children: [
// PositionedTransition은 스택에서만 작동
PositionedTransition(
rect: _controller,
child: Container(color: Colors.blue),
),
],
),
);
}
}
728x90
'Usage > Flutter' 카테고리의 다른 글
[Flutter/Animation] AnimatedSwitcher를 활용한 위젯 바꿀때 애니메이션 효과 넣기 (0) | 2021.06.24 |
---|---|
[Flutter/Animation] PositionedTransition을 직접 구현해보기 (0) | 2021.06.24 |
[Flutter/Animation] ScaleTransition을 활용한 컨테이너 사이즈 애니메이션 (0) | 2021.06.24 |
[Flutter/Animation] AnimatedContainer를 활용한 오른쪽에서 왼쪽으로 이동하는 컨테이너 (0) | 2021.06.24 |
[Flutter] GetX - 좀 더 쉽게 controller 접근하기 (0) | 2021.06.17 |