Last active
May 30, 2020 13:32
-
-
Save vijayinyoutube/d4ec9446fd74be1a2ead232b1c9ad122 to your computer and use it in GitHub Desktop.
AnimatedContainer
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() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Animated Container', | |
theme: ThemeData(), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
double animationValue = 10; | |
bool pressed = false; | |
final random = Random(); | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("AnimatedContainer")), | |
body: Center( | |
child: Padding( | |
padding: EdgeInsets.symmetric(horizontal: 10), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
pressed == false | |
? AnimatedContainer( | |
duration: Duration(seconds: 1), | |
curve: Curves.fastOutSlowIn, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(15), | |
color: Colors.transparent), | |
width: 28, | |
height: 28, | |
child: CircularProgressIndicator( | |
valueColor: | |
new AlwaysStoppedAnimation<Color>(Colors.red), | |
), | |
) | |
: AnimatedContainer( | |
duration: Duration(seconds: 1), | |
curve: Curves.fastOutSlowIn, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(15), | |
color: Colors.green), | |
width: (animationValue) * animationValue, | |
height: 50, | |
child: Center( | |
child: Text( | |
"Connected :)", | |
style: TextStyle(fontSize: 25, color: Colors.white), | |
), | |
), | |
), | |
SizedBox(height: 10), | |
Container( | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(10), | |
color: Colors.blue), | |
child: FlatButton( | |
onPressed: () { | |
setState(() { | |
pressed = true; | |
animationValue = animationValue + 10; | |
}); | |
}, | |
child: Text( | |
"Refresh", | |
style: TextStyle(fontSize: 25, color: Colors.white), | |
), | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Author
vijayinyoutube
commented
May 30, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment