Created
June 29, 2020 16:55
-
-
Save dpossas/601c9faa1fe09b295433f78870758629 to your computer and use it in GitHub Desktop.
AnimatedContainer Test
This file contains hidden or 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 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
_MyWidgetState createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
double currentWidgetWidth = 0.0; | |
double _newWidgetWidth; | |
@override | |
void initState() { | |
_newWidgetWidth = MediaQuery.of(context).size.width; | |
Future.delayed(Duration(seconds: 1)).then((value) => animate()); | |
super.initState(); | |
} | |
void animate() { | |
setState(() { | |
currentWidgetWidth = _newWidgetWidth; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.grey, | |
width: MediaQuery.of(context).size.width, | |
height: 50, | |
child: AnimatedContainer( | |
duration: Duration(seconds: 1), | |
width: currentWidgetWidth, | |
height: 50, | |
child: Text( | |
"LABEL", | |
textAlign: TextAlign.center, | |
), | |
decoration: BoxDecoration( | |
color: Colors.green, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment