Created
July 31, 2019 09:14
-
-
Save ipondroid/88dab615fb9b5ebafe791633d57c5e7a to your computer and use it in GitHub Desktop.
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 _ClickCounterState extends State<ClickCounter> { | |
int _count = 0; | |
var keys = [1, 2, 3]; | |
var colors = [Colors.red, Colors.blue, Colors.green]; | |
var borderRadius = [50.0, 30.0, 0.0]; | |
Widget createBox(int key) => Container( | |
decoration: BoxDecoration( | |
color: colors[key], | |
borderRadius: BorderRadius.circular(borderRadius[key]), | |
), | |
width: 200.0, | |
height: 100.0, | |
key: ValueKey<int>(key), | |
); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Material( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
AnimatedSwitcher( | |
duration: const Duration(milliseconds: 500), | |
transitionBuilder: (Widget child, Animation<double> animation) { | |
return ScaleTransition(child: child, scale: animation); | |
}, | |
child: createBox(_count), | |
), | |
Container(height: 200.0), | |
RaisedButton( | |
child: const Text('Switch'), | |
onPressed: () { | |
setState(() { | |
if(_count > 1) { | |
_count = 0; | |
} else { | |
_count++; | |
} | |
}); | |
}, | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment