hero_container 1.0.2 copy "hero_container: ^1.0.2" to clipboard
hero_container: ^1.0.2 copied to clipboard

Smooth animated transitions between widgets using snapshot-based animations. Inspired by OpenContainer with enhanced performance for complex layouts.

example/main.dart

import 'package:flutter/material.dart';
import 'package:hero_container/hero_container.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Example(),
      ),
    );
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: HeroContainer(
        // Shape for the closed state with rounded corners
        closedShape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(15),
        ),

        // Builder for the expanded/opened state - shows a full screen scaffold.
        openedBuilder: (BuildContext context) {
          return Scaffold(
            appBar: AppBar(title: Text("Expanded View")),
            body: Center(
              child: Text("Hello, World!", style: TextStyle(fontSize: 32)),
            ),
          );
        },

        // Builder for the collapsed/closed state -
        // shows a button that triggers the transition.
        closedBuilder: (BuildContext context, VoidCallback action) {
          return TextButton(
            // Call this to trigger the hero container transition.
            onPressed: action,
            child: Text("Tap to expand", style: TextStyle(fontSize: 50)),
          );
        },
      ),
    );
  }
}
6
likes
160
points
17
downloads

Publisher

verified publisherttangkong.dev

Weekly Downloads

Smooth animated transitions between widgets using snapshot-based animations. Inspired by OpenContainer with enhanced performance for complex layouts.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on hero_container