Upgrade to Pro — share decks privately, control downloads, hide ads and more …

【Flutter】アニメーション初心者から抜け出そう

 【Flutter】アニメーション初心者から抜け出そう

【背景】
Flutterエンジニアコミュニティ内で行った勉強会の共有資料です

【内容】
Flutterアニメーションの応用について

【元記事】
https://zenn.dev/heyhey1028/articles/a9ee3695cfcf63
https://zenn.dev/heyhey1028/articles/8752d61f522f50
https://zenn.dev/heyhey1028/articles/222e2851e9d97f
https://zenn.dev/heyhey1028/articles/10492c3884a45a

【サンプルコード】
https://github.com/heyhey1028/flutter_samples/tree/main/samples/master_animation

heyhey1028

April 20, 2023
Tweet

More Decks by heyhey1028

Other Decks in Programming

Transcript

  1. Curve
 1. Tweenを変化させる
 2. アニメーションへの追加効果
 _tween = Tween<Alignment>( begin: Alignment.topLeft,

    end: Alignment.bottomRight, ).chain( CurveTween( curve: Curves.fastLinearToSlowEaseIn, ), );
  2. Animation
 1. Widgetに適用するアニメーションそのもの
 2. AnimationControlerとTweenとCurveを掛け 合わせて作る
 _animation = AnimationController( vsync:

    this, duration: const Duration(milliseconds: 1000), ).drive( Tween<Alignment>( begin: Alignment.topLeft, end: Alignment.bottomRight, ).chain( CurveTween( curve: Curves.fastLinearToSlowEaseIn, ), ), );
  3. AnimatedWidgetを使う
 1. AnimatedWidgetを継承させたWidgetに切り出す
 2. 引数にAnimationを渡す
 class AnimatingText extends AnimatedWidget {

    const AnimatingText({ super.key, required Animation<Alignment> animation, }) : super(listenable: animation); @override Widget build(BuildContext context) { return Align( alignment: _alignment.value, child: Text('Hello world!'), )
  4. AnimatedAlign( alignment: Alignment, duration: const Duration(), child: Text(‘Hello World’), ),

    late AnimationController controller; late Tween <Alignment > tween; final Curve curve = Curves .ease; late Animation <Alignment > animation; @override void initState () { controller = AnimationController ( duration: const Duration (seconds: 3), vsync: this, // <<< 2. passing this class to AnimationController ); tween = Tween ( // <<< 3. declare Tween with the beginning value and ending value begin: Alignment .topCenter, end: Alignment .bottomCenter, ); tween. chain ( CurveTween (curve: curve)); // <<< 4. apply transition curves to Tween animation = controller. drive ( tween); // <<< 5. create Animation from AnimationController and Tween super.initState (); } @override void dispose () { controller. dispose (); super.dispose (); } body: AnimatedBuilder ( animation: animation, builder: (context, _) { return Align ( alignment: animation .value, // <<< 6. bind Animation to the widget you want to animate child: const Text('Hello world!' ), ); }, ),
  5. AnimatedSlide
 AnimatedAlign
 AnimatedScale
 AnimatedOpacity
 AnimatedRotation
 AnimatedSize
 AnimatedPositioned
 …
 SlideTransition
 AlignTransition


    ScaleTransition
 FadeTransition
 RotationTransition
 SizeTransition
 PositionedTransition
 …
 Animated〇〇
 〇〇Transition