Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created July 19, 2024 15:51
Show Gist options
  • Save fredgrott/d7f688641f2735f677bd703e6d47128c to your computer and use it in GitHub Desktop.
Save fredgrott/d7f688641f2735f677bd703e6d47128c to your computer and use it in GitHub Desktop.
build animated item
// 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