Flutter Animation : AnimatedPositioned

mobile academy


import 'package:flutter/material.dart';

class PositionAnimation extends StatefulWidget {
  const PositionAnimation({Key? key}) : super(key: key);

  @override
  State<PositionAnimation> createState() => _PositionAnimationState();
}

class _PositionAnimationState extends State<PositionAnimation> {
  double _height = 200;
  double _width = 200;
  double _position = 20;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Stack(
          children: [
            AnimatedPositioned(
              top: _position,
              duration: const Duration(milliseconds: 800),
              curve: Curves.elasticIn,
              child: Image.asset(
                'assets/user1.jpg',
                width: _width,
                height: _height,
              ), 
            ),

            Positioned(
              bottom: 20,
              child: ElevatedButton(
                onPressed: () {
                  setState(() {
                    _position = _position == 20 ? 200 : 20;  
                    _width = _width == 200 ? 100 : 200;               
                  });
                  
                }, 
                child: const Text('Click Me!'),
              ),
            ),

            


          ],
        )    ),
    );
  }
}
Select your currency
INR Indian rupee