Skip to content

Instantly share code, notes, and snippets.

@RedBrogdon
Last active October 20, 2020 03:02
Show Gist options
  • Save RedBrogdon/f5f13bf4787865d4ab21c35a4f8f58e2 to your computer and use it in GitHub Desktop.
Save RedBrogdon/f5f13bf4787865d4ab21c35a4f8f58e2 to your computer and use it in GitHub Desktop.
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