Created
July 19, 2024 15:51
-
-
Save fredgrott/d7f688641f2735f677bd703e6d47128c to your computer and use it in GitHub Desktop.
build animated item
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
// Copyright 2024 Fredrick Allan Grott. All rights reserved. | |
// Use of this source code is governed by a BSD-style | |
// license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
/// Wraps the item to animate with animation | |
/// in preparation to be used the auto animate | |
/// list and grid methods. | |
Widget Function( | |
BuildContext context, | |
int index, | |
Animation<double> animation, | |
) animationItemBuilder( | |
Widget Function(int index) child, { | |
EdgeInsets padding = EdgeInsets.zero, | |
}) => | |
( | |
BuildContext context, | |
int index, | |
Animation<double> animation, | |
) => | |
FadeTransition( | |
opacity: Tween<double>( | |
begin: 0, | |
end: 1, | |
).animate(animation), | |
child: SlideTransition( | |
position: Tween<Offset>( | |
begin: const Offset(0, -0.1), | |
end: Offset.zero, | |
).animate(animation), | |
child: Padding( | |
padding: padding, | |
child: child(index), | |
), | |
), | |
); | |
/// Wraps the animation around a child widget | |
/// so that we can use the AnimateIfVisibleWrapper | |
Widget Function( | |
BuildContext context, | |
Animation<double> animation, | |
) animationBuilder( | |
Widget child, { | |
double xOffset = 0, | |
EdgeInsets padding = EdgeInsets.zero, | |
}) => | |
( | |
BuildContext context, | |
Animation<double> animation, | |
) => | |
FadeTransition( | |
opacity: Tween<double>( | |
begin: 0, | |
end: 1, | |
).animate(animation), | |
child: SlideTransition( | |
position: Tween<Offset>( | |
begin: Offset(xOffset, 0.1), | |
end: Offset.zero, | |
).animate(animation), | |
child: Padding( | |
padding: padding, | |
child: child, | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment