๐ late ํค์๋๋ก ์ ์ธ๋ animationController๊ฐ initState()์์ ์ด๊ธฐํ๋์ง ์์๊ฑฐ๋, ์์ ฏ์ด ์ฌ์ฉ๋๊ธฐ ์ ์ ์ด๊ธฐํ๋์ง ์์์ ๋ ๋ฐ์ํ๋ค.
๐ ์์ธ
โ ํด๊ฒฐ ๋ฐฉ๋ฒ
class _MyWidgetState extends State<MyWidget> with SingleTickerProviderStateMixin {
late AnimationController animationController;
void initState() {
super.initState();
// ๐น AnimationController ์ด๊ธฐํ
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
}
void dispose() {
// ๐น AnimationController๋ ๋ฐ๋์ dispose()์์ ์ ๋ฆฌ
animationController.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Container();
}
}
class _MyWidgetState extends State<MyWidget> with SingleTickerProviderStateMixin {
final AnimationController animationController;
_MyWidgetState()
: animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
void dispose() {
animationController.dispose();
super.dispose();
}
}
initState ์ถ๊ฐ ํ, ์ค๋ฅ๊ฐ ์ฌ๋ผ์ง ๊ฒ์ ํ์ธํ ์ ์์์!