Skip to content

Instantly share code, notes, and snippets.

@codediodeio

codediodeio/main.dart

Last active May 17, 2019
Embed
What would you like to do?
An animated box shadow button with Dart 2.3 collection if/for
class CircleStack extends StatefulWidget {
@override
_CircleStackState createState() => _CircleStackState();
}
class _CircleStackState extends State<CircleStack> {
bool open = true;
@override
Widget build(BuildContext context) {
return Center(
child: AnimatedContainer(
width: 80,
height: 80,
duration: Duration(seconds: 2),
curve: Curves.easeOutQuart,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.purple,
boxShadow: [
if (open) // 👈
for (var i = 0; i < 5; i += 1) // 👈
BoxShadow(
spreadRadius: i * 40.0,
color: Colors.purple.withAlpha((255 / (i + 1)).toInt()))
],
),
child: IconButton(
icon: Icon(Icons.mic, color: Colors.white),
onPressed: () {
setState(() {
open = !open;
});
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment