Skip to content

Instantly share code, notes, and snippets.

@jtmcdole
Created August 5, 2020 17:02
Show Gist options
  • Save jtmcdole/a542acd18dd8cd9cc244ee87ca0b4cfc to your computer and use it in GitHub Desktop.
Save jtmcdole/a542acd18dd8cd9cc244ee87ca0b4cfc to your computer and use it in GitHub Desktop.
flutter ClipRect + SlideTransition
// Flutter code sample for SlideTransition
// The following code implements the [SlideTransition] as seen in the video
// above:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
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: Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<Offset> _offsetAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: true);
_offsetAnimation = Tween<Offset>(
begin: Offset.zero,
end: const Offset(0.0, 1.5),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.easeIn,
));
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return ClipRect(
child: SlideTransition(
position: _offsetAnimation,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: FlutterLogo(size: 150.0),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment