Last active
December 22, 2019 18:09
-
-
Save mirkancal/70755268e011cda95f6f918421d9dbcc 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
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() async { | |
runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: AnimatedContainerExample(), | |
), | |
); | |
} | |
class AnimatedContainerExample extends StatefulWidget { | |
@override | |
_AnimatedContainerExampleState createState() => | |
_AnimatedContainerExampleState(); | |
} | |
class _AnimatedContainerExampleState extends State<AnimatedContainerExample> { | |
Color color; | |
double borderRadius; | |
double margin; | |
@override | |
void initState() { | |
super.initState(); | |
color = Colors.deepPurple; | |
borderRadius = randomBorderRadius(); | |
margin = randomMargin(); | |
} | |
void change() { | |
setState(() { | |
margin = randomMargin(); | |
borderRadius = randomBorderRadius(); | |
color = randomColor(); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
height: 500, | |
width: 300, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: <Widget>[ | |
SizedBox( | |
width: 128, | |
height: 128, | |
child: AnimatedContainer( | |
curve: Curves.bounceIn, | |
duration: Duration( | |
milliseconds: 600, | |
), | |
margin: EdgeInsets.all(margin), | |
decoration: BoxDecoration( | |
color: color, | |
borderRadius: BorderRadius.circular(borderRadius), | |
), | |
), | |
), | |
FloatingActionButton.extended( | |
label: Text("Değiştir"), | |
icon: Icon(Icons.change_history), | |
onPressed: change, | |
) | |
], | |
), | |
); | |
} | |
} | |
double randomBorderRadius() { | |
return Random().nextDouble() * 64; | |
} | |
double randomMargin() { | |
return Random().nextDouble() * 64; | |
} | |
Color randomColor() { | |
return Color.fromARGB( | |
Random().nextInt(256), | |
Random().nextInt(256), | |
Random().nextInt(256), | |
Random().nextInt(256), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment