Last active
October 20, 2020 03:02
-
-
Save RedBrogdon/f5f13bf4787865d4ab21c35a4f8f58e2 to your computer and use it in GitHub Desktop.
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 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
static const data = ['One', 'Two', 'Three', 'Four', 'Five', 'Six']; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: Scaffold( | |
body: Column( | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: List.generate(data.length, (i) { | |
return FlyingButton(data[i], i * 200); | |
}), | |
), | |
), | |
); | |
} | |
} | |
class FlyingButton extends StatefulWidget { | |
final String text; | |
final int delay; | |
FlyingButton(this.text, this.delay); | |
@override | |
_FlyingButtonState createState() => _FlyingButtonState(); | |
} | |
class _FlyingButtonState extends State<FlyingButton> | |
with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
Animation<Offset> _offsetAnimation; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController( | |
duration: Duration(milliseconds: 400 + widget.delay), | |
vsync: this, | |
)..forward(); | |
_offsetAnimation = Tween<Offset>( | |
begin: const Offset(-1, 0.0), | |
end: Offset.zero, | |
).animate(CurvedAnimation( | |
parent: _controller, | |
curve: Curves.easeOut, | |
)); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return SlideTransition( | |
position: _offsetAnimation, | |
child: Padding( | |
padding: const EdgeInsets.symmetric( | |
horizontal: 16, | |
vertical: 8, | |
), | |
child: RaisedButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(10), | |
), | |
child: Text(widget.text), | |
onPressed: () {}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment