import 'package:flutter/material.dart';
// entry point of your application
// passing the stateless widget
// inside the runApp Method
void main() => runApp(const SizeTransitionGeeksExample());
// Stateless widget named as SizeTransitionGeeksExample
class SizeTransitionGeeksExample extends StatelessWidget {
const SizeTransitionGeeksExample({Key? key}); // Widget for the main app
@override
Widget build(BuildContext context) {
// Material app
return const MaterialApp(
home: GfgSizeTransition(),
);
}
}
// Statefull widget named as GfgSizeTransition
class GfgSizeTransition extends StatefulWidget {
const GfgSizeTransition({Key? key}); // Widget for the size transition
@override
State<GfgSizeTransition> createState() => _GfgSizeTransitionState();
}
/// The following code sets up animations and their curves.
class _GfgSizeTransitionState extends State<GfgSizeTransition>
with TickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 3),
vsync: this,
)..repeat(); // Animation controller with a repeating animation
late final Animation<double> _animationa = CurvedAnimation(
parent: _controller,
curve: Curves.bounceIn,
); // Animation with a bounce-in curve
late final Animation<double> _animationb = CurvedAnimation(
parent: _controller,
curve: Curves.slowMiddle,
); // Animation with a slow middle curve
late final Animation<double> _animationc = CurvedAnimation(
parent: _controller,
curve: Curves.fastLinearToSlowEaseIn,
); // Animation with a fast linear to slow ease-in curve
late final Animation<double> _animationd = CurvedAnimation(
parent: _controller,
curve: Curves.easeOutQuint,
); // Animation with an ease-out quint curve
late final Animation<double> _animatione = CurvedAnimation(
parent: _controller,
curve: Curves.decelerate,
); // Animation with a decelerate curve
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
title: const Text("GFG Size Transition")), // App bar with a title
// Column contains SizeTrasition Widget
body: Column(
children: [
Container(
height: 500, // Container with a fixed height
child: Column(
children: [
// SizeTransition widget
SizeTransition(
sizeFactor: _animationa,
axis: Axis.horizontal,
axisAlignment: -1,
child: Center(
child: Image.network(
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210419113249/gfg-new-logo-min.png'),
),
),
// SizeTransition widgets with different animations and alignments
SizeTransition(
sizeFactor: _animationb,
axis: Axis.horizontal,
axisAlignment: -1,
child: Center(
child: Image.network(
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210419113249/gfg-new-logo-min.png'),
),
),
SizeTransition(
sizeFactor: _animationc,
axis: Axis.horizontal,
axisAlignment: -1,
child: Center(
child: Image.network(
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210419113249/gfg-new-logo-min.png'),
),
),
SizeTransition(
sizeFactor: _animationd,
axis: Axis.horizontal,
axisAlignment: -1,
child: Center(
child: Image.network(
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210419113249/gfg-new-logo-min.png'),
),
),
SizeTransition(
sizeFactor: _animatione,
axis: Axis.vertical,
axisAlignment: -1,
child: Center(
child: Image.network(
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210419113249/gfg-new-logo-min.png'),
),
),
],
),
),
// sizedbox widget
SizedBox(child: const Text("More Explore yourself...")) // Text widget at the end
],
),
);
}
}