import 'dart:math';
import 'package:flutter/material.dart';
class SwitcherAnimation extends StatefulWidget {
const SwitcherAnimation({Key? key}) : super(key: key);
@override
State<SwitcherAnimation> createState() => _SwitcherAnimationState();
}
class _SwitcherAnimationState extends State<SwitcherAnimation> {
int _size = 200;
final Random _random = Random();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
children: [
const SizedBox(height: 50,),
AnimatedSwitcher(
duration: const Duration(milliseconds: 800),
transitionBuilder: (child, animation) {
return ScaleTransition(scale: animation,child: child,);
},
child: Image.asset(
key: ValueKey(_size),
'assets/user1.jpg',
width: 200,
height: 200,
),
),
const SizedBox(height: 8,),
ElevatedButton(
onPressed: () {
setState(() {
_size = _random.nextInt(300);
});
},
child: const Text('Click Me!'),
)
],
),
),
);
}
}