Exp-8
Exp-8
a)
Animations
Program:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: AnimatedLogo(),
);
@override
with SingleTickerProviderStateMixin {
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
);
..addListener(() {
setState(() {
// The state that has changed here is the animation object’s value.
});
});
controller.forward();
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Container(
height: animation.value,
width: animation.value,
child: FlutterLogo(),
),
),
);
@override
void dispose() {
controller.dispose();
super.dispose();
Output:
EXPERIMENT :8.b)
Types of Animations
Program:
Program:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
Widget build(BuildContext context) {
return MaterialApp(
home: AnimationExperiment(),
);
@override
with SingleTickerProviderStateMixin {
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
);
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(_controller);
_slideAnimation = Tween<Offset>(
end: Offset.zero,
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.easeInOut,
));
_scaleAnimation = Tween<double>(
begin: 0.5,
end: 1.0,
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.easeInOut,
));
_controller.forward();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FadeTransition(
opacity: _fadeAnimation,
child: Container(
width: 200,
height: 200,
color: Colors.blue,
child: Center(
child: Text(
'Fade Animation',
),
),
),
),
SizedBox(height: 20),
SlideTransition(
position: _slideAnimation,
child: Container(
width: 200,
height: 200,
color: Colors.green,
child: Center(
child: Text(
'Slide Animation',
),
),
),
),
SizedBox(height: 20),
ScaleTransition(
scale: _scaleAnimation,
child: Container(
width: 200,
height: 200,
color: Colors.orange,
child: Center(
child: Text(
'Scale Animation',
),
),
),
),
],
),
),
);
OUTPUT: