画面収録 2024-12-02 15.39.19.mov

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: AnimatedButton(),
        ),
      ),
    );
  }
}

class AnimatedButton extends StatefulWidget {
  @override
  _AnimatedButtonState createState() => _AnimatedButtonState();
}

class _AnimatedButtonState extends State<AnimatedButton> {
  double shadowBlur = 5;
  final Color notPressedColor = const Color(0xffFF7049);
  final Color pressedColor = const Color(0xffFFDF5E);
  Color nowColor = const Color(0xffFF7049);
  final double defalutSize = 200;
  final double zoomSize = 250;
  double buttonSize = 200;

  void _animateButton() {
    setState(() {
      buttonSize = (buttonSize == defalutSize) ? zoomSize :defalutSize;
      shadowBlur = (shadowBlur) == 5 ? 15 : 5; // シャドウの強さを変更
      nowColor = (nowColor == notPressedColor) ? pressedColor : notPressedColor; // 色を変更
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: _animateButton,
      child: AnimatedContainer(
        duration: Duration(milliseconds: 150),      // 変化にかける時間
        width: buttonSize,
        height: buttonSize,
        decoration: BoxDecoration(
          color: nowColor,
          borderRadius: BorderRadius.circular(1000),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.2),
              blurRadius: shadowBlur,
              offset: Offset(0, 5),
            ),
          ],
        ),
        child: Center(
          child: Text(
            '押す',
            style: TextStyle(color: Colors.white, fontSize: 40),
          ),
        ),
      ),
    );
  }
}