Skip to content

Instantly share code, notes, and snippets.

@moux2003
Created June 24, 2020 16:00
Show Gist options
  • Select an option

  • Save moux2003/c2e47163b9b04ca25d9dfbcf5de546ba to your computer and use it in GitHub Desktop.

Select an option

Save moux2003/c2e47163b9b04ca25d9dfbcf5de546ba to your computer and use it in GitHub Desktop.
animation slide via AnimatedBuilder
class _Mobile extends StatelessWidget {
final Widget child;
_Mobile({this.child});
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width / 3;
int elapsed = 1;
return Center(
child: Container(
height: MediaQuery.of(context).size.height,
width: width,
child: AnimatedSwitcher(
key: ValueKey(elapsed),
duration: Duration(milliseconds: 500),
transitionBuilder: (child, animation) {
final inAnimation = Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0)).animate(animation);
final outAnimation = Tween<Offset>(begin: Offset(-1.0, 0.0), end: Offset(0.0, 0.0)).animate(animation);
if (child.key == ValueKey(elapsed)) {
return ClipRect(
child: SlideTransition(
position: outAnimation,
child: child,
),
);
} else {
return ClipRect(
child: SlideTransition(
position: inAnimation,
child: child,
),
);
}
},
child: this.child,
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment