Skip to content

Instantly share code, notes, and snippets.

@codediodeio
Last active May 17, 2019 00:58
Show Gist options
  • Save codediodeio/6d9423843731327d56dfe6df352e4dbc to your computer and use it in GitHub Desktop.
Save codediodeio/6d9423843731327d56dfe6df352e4dbc to your computer and use it in GitHub Desktop.
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