Flutter card to fullscreen animation with drag-to-dismiss
A product card expanding to fullscreen and dragged back

A product card that grows into a full product page is one of the most common transitions in mobile apps. Done by hand in Flutter, it usually needs a custom route, measured bounds, Hero tags for each element and extra work to make the page dismissible with a gesture. With ExpandableAnimation it is one wrapper.

The problem

  • The card should appear to become the page, not slide a new page over it.
  • Closing the page should return the card to its exact place, even if the grid scrolled or the window resized.
  • Users expect to swipe the page away, not only tap a back button.

The solution

class ProductTile extends StatelessWidget {
  const ProductTile({super.key, required this.product});

  final Product product;

  @override
  Widget build(BuildContext context) {
    final scheme = Theme.of(context).colorScheme;
    return ExpandableAnimation(
      borderRadius: BorderRadius.circular(20),
      collapsedColor: scheme.surfaceContainerHigh,
      expandedColor: scheme.surface,
      semanticLabel: 'Open ${product.name}',
      expandedBuilder: (context) => ProductDetailsPage(product: product),
      child: ProductCard(product: product),
    );
  }
}

Inside the details page, add a close button:

IconButton(
  tooltip: 'Close',
  icon: const Icon(Icons.close),
  onPressed: () => ExpandableAnimation.of(context).collapse(),
)

How it behaves

  • The card's bounds, corner radius (20 → 0) and color morph to fill the screen while the card content cross-fades into the page.
  • Drag the page down to shrink it; release past 20% of its height (or fling) to send it back.
  • The back button and Escape collapse it; a PopScope in the page can prevent that.
  • Put many tiles in a grid; each expands independently.

Tip: on large windows a full-width page can feel heavy. Use mode: const ExpandableAnimationMode.dialog() to open a centered panel instead.

Try it

Open the product card demo, or read about how the container transform works.