[TIL]221006 - Flutter 애니메이션(1)

Jimin·2022년 10월 10일
0

제스처 감지

애니메이션 적용x

 GestureDetector( //제스처 감지
        onTap: () {
        setState(() {
          _selected = !_selected;
        });
        },
          child: Container(
            color: Colors.blueGrey,
            width: _selected? 250 : 310,
            height: _selected? 250: 310,
          ),
        ),

애니메이션 적용

GestureDetector( //제스처 감지
        onTap: () {
        setState(() {
          _selected = !_selected;
        });
        },
          child: AnimatedContainer(
              color: Colors.blueGrey,
              width: _selected? 250 : 310,
              height: _selected? 250: 310, 
              duration: Duration(milliseconds: 500),
        ),
        ),

TwinAnimationBuilder

        Center(
          child: Center(
            child: TweenAnimationBuilder(
              tween: Tween<double>(begin: 0, end: sizeValue),
              duration: Duration(seconds: 1),
              builder:
                  (_, double size, __) {
                return IconButton(
                  onPressed: () {
                    setState(() {
                      sizeValue = sizeValue == 100.0 ? 200.0 : 100.0;
                    });
                  },
                  icon: Icon(Icons.sentiment_satisfied),
                  iconSize: size,
                  color: Colors.blue,
                );
              },
            ),
          ),
        )

RotationTransition

        body:
        RotationTransition(
          turns: _animation,
          alignment: Alignment.center,
          child: Center(
            child: IconButton(
              icon: Icon(
                Icons.sentiment_satisfied,
              ),
              iconSize: 100,
              onPressed: () {
                if (_controller.duration?.inSeconds == 1) {
                  _controller.duration = const Duration(seconds: 3);
                } else {
                  _controller.duration = const Duration(seconds: 1);
                }
                _controller.repeat();
              },
            ),
          ),
        )

0개의 댓글