Skip to content

Instantly share code, notes, and snippets.

@vijayinyoutube
Last active May 30, 2020 13:32
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 vijayinyoutube/d4ec9446fd74be1a2ead232b1c9ad122 to your computer and use it in GitHub Desktop.
Save vijayinyoutube/d4ec9446fd74be1a2ead232b1c9ad122 to your computer and use it in GitHub Desktop.
AnimatedContainer
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),
),
),
),
],
),
),
),
);
}
}
@vijayinyoutube
Copy link
Author

vijayinyoutube commented May 30, 2020

Output

ezgif com-video-to-gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment