Created
September 12, 2020 15:31
-
-
Save ibhavikmakwana/98c38403579ee3a1e5d8f786c14b87c8 to your computer and use it in GitHub Desktop.
WhatsApp Like Swipe to Reply animation
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 { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> | |
with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
Animation<Offset> animation; | |
@override | |
initState() { | |
super.initState(); | |
_controller = AnimationController( | |
vsync: this, | |
duration: const Duration(milliseconds: 200), | |
); | |
animation = Tween( | |
begin: const Offset(0.0, 0.0), | |
end: const Offset(0.3, 0.0), | |
).animate( | |
CurvedAnimation( | |
curve: Curves.decelerate, | |
parent: _controller, | |
), | |
); | |
} | |
@override | |
dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: GestureDetector( | |
onHorizontalDragUpdate: (details) { | |
if (details.delta.dx > 1) { | |
_controller.forward().whenComplete(() => _controller.reverse()); | |
} | |
}, | |
child: SlideTransition( | |
position: animation, | |
child: Container( | |
color: Colors.red.shade200, | |
margin: const EdgeInsets.symmetric(horizontal: 16.0), | |
padding: | |
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), | |
child: Text('Hello There! How are you?'), | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment