An animated box shadow button with Dart 2.3 collection if/for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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