Skip to content

Instantly share code, notes, and snippets.

@iapicca
Created November 6, 2019 12:17
Show Gist options
  • Select an option

  • Save iapicca/8b557eebb34e8c03a98db03dd9d118ac to your computer and use it in GitHub Desktop.

Select an option

Save iapicca/8b557eebb34e8c03a98db03dd9d118ac to your computer and use it in GitHub Desktop.
AnimatedContainer
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp>{
static const Duration _duration = Duration(seconds: 1);
bool _state = true;
double _width = 2.0;
Color _color = Colors.red;
void _play() => setState((){
_state=!_state;
_color= _state?Colors.red:Colors.blue;
_width = _state?2.0:20.0;
});
@override
Widget build(BuildContext context)=> Scaffold(
body: GestureDetector(
onTap:()=> _play(),
child: Padding(
padding: EdgeInsets.all(40),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerRight,
child:AnimatedContainer(
width: 80,
height: 80,
duration: _duration,
color: _color,
),),
Align(
alignment: Alignment.centerLeft,
child:AnimatedContainer(
width: 80,
height: 80,
duration: _duration,
decoration: BoxDecoration(
color: _color,
border: Border.all(
color: Colors.black,
width: _width,
),),),),
],
),),),);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment