Skip to content

Instantly share code, notes, and snippets.

@CoderNamedHendrick
Created October 7, 2022 04:17
Show Gist options
  • Save CoderNamedHendrick/8c7d13fea1449fd2d6948a1aaba96b1d to your computer and use it in GitHub Desktop.
Save CoderNamedHendrick/8c7d13fea1449fd2d6948a1aaba96b1d to your computer and use it in GitHub Desktop.
Pulsing scale animation
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
late AnimationController _animation;
late Animation<double> _radius;
late Animation<double> _iconRadius;
static double radius = 48;
static double iconRadius = 24;
@override
void initState() {
super.initState();
_animation = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1200),
);
_radius =
Tween<double>(end: radius, begin: radius * 1.56).animate(_animation);
_iconRadius = Tween<double>(end: iconRadius, begin: iconRadius * 1.56)
.animate(_animation);
_animation.addStatusListener((status) {
if (status == AnimationStatus.completed) {
_animation.reset();
} else if (status == AnimationStatus.dismissed) {
_animation.forward();
}
});
_animation.forward();
}
@override
void dispose() {
_animation.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return Container(
height: _radius.value,
width: _radius.value,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.purple,
boxShadow: [
BoxShadow(
color: Colors.purpleAccent.withOpacity(0.2),
spreadRadius: 10,
blurRadius: 3),
],
),
alignment: Alignment.center,
child: Icon(Icons.mic_outlined, size: _iconRadius.value),
);
},
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment