Skip to content

Instantly share code, notes, and snippets.

@mirkancal
Last active December 22, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirkancal/70755268e011cda95f6f918421d9dbcc to your computer and use it in GitHub Desktop.
Save mirkancal/70755268e011cda95f6f918421d9dbcc to your computer and use it in GitHub Desktop.
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