Skip to content

Instantly share code, notes, and snippets.

@ashutoshsr7
Created May 28, 2024 12:06
Show Gist options
  • Save ashutoshsr7/66fb8e40592cd2c7549a1f9147423218 to your computer and use it in GitHub Desktop.
Save ashutoshsr7/66fb8e40592cd2c7549a1f9147423218 to your computer and use it in GitHub Desktop.
Using Interval
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: IntervalDemo(),
);
}
}
class IntervalDemo extends StatefulWidget {
@override
_IntervalDemoState createState() => _IntervalDemoState();
}
class _IntervalDemoState extends State<IntervalDemo> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<Color?> _colorAnimation;
late Animation<double> _sizeAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 4),
vsync: this,
);
_colorAnimation = ColorTween(begin: Colors.blue, end: Colors.red).animate(
CurvedAnimation(
parent: _controller,
curve: Interval(0.0, 0.5, curve: Curves.easeIn),
),
) as Animation<Color?>;
_sizeAnimation = Tween<double>(begin: 50.0, end: 150.0).animate(
CurvedAnimation(
parent: _controller,
curve: Interval(0.5, 1.0, curve: Curves.easeOut),
),
);
_controller.repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Interval Demo')),
body: Center(
child: AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Container(
width: _sizeAnimation.value,
height: _sizeAnimation.value,
color: _colorAnimation.value,
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment