Skip to content

Instantly share code, notes, and snippets.

@neiljaywarner
Created November 2, 2022 20:10
Show Gist options
  • Save neiljaywarner/719a2ed6819e1b75f98068ed3857cc23 to your computer and use it in GitHub Desktop.
Save neiljaywarner/719a2ed6819e1b75f98068ed3857cc23 to your computer and use it in GitHub Desktop.
star wars crawl excpet rtl-slidetransistion example modified only with 2 lines or so
import 'package:flutter/material.dart';
// see https://api.flutter.dev/flutter/widgets/SlideTransition-class.html
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget>
with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: false);
late final Animation<Offset> _offsetAnimation = Tween<Offset>(
begin: Offset.zero,
end: const Offset(1.5, 0.0),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.linear,
));
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return SlideTransition(
position: _offsetAnimation,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Star Wars'),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment