A widget which implicitly launches a hero animation when its position changed within the same route.

Overview

local_hero

Pub

A widget which implicitly launches a hero animation when its position changed within the same route.

Overview

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  local_hero:

In your library add the following import:

import 'package:local_hero/local_hero.dart';

Usage

To be animated implicitly, a widget needs to be surrounded by a LocalHero widget with a unique tag:

const LocalHero(
    tag: 'my_widget_tag',
    child: MyWidget(),
),

A LocalHero widget must have a LocalHeroScope ancestor which hosts the animations properties (duration, curve, etc.). At each frame we must have only one LocalHero per tag, per LocalHeroScope.

The following example shows the basic usage of a LocalHero widget:

class _LocalHeroPage extends StatelessWidget {
  const _LocalHeroPage({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: LocalHeroScope(
          duration: const Duration(milliseconds: 300),
          curve: Curves.easeInOut,
          child: const _LocalHeroPlayground(),
        ),
      ),
    );
  }
}

class _LocalHeroPlayground extends StatefulWidget {
  const _LocalHeroPlayground({
    Key key,
  }) : super(key: key);

  @override
  _LocalHeroPlaygroundState createState() => _LocalHeroPlaygroundState();
}

class _LocalHeroPlaygroundState extends State<_LocalHeroPlayground> {
  AlignmentGeometry alignment = Alignment.topLeft;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: Padding(
            padding: const EdgeInsets.all(8),
            child: Align(
              alignment: alignment,
              child: const LocalHero(
                tag: 'id',
                child: _Box(),
              ),
            ),
          ),
        ),
        RaisedButton(
          onPressed: () {
            setState(() {
              alignment = alignment == Alignment.topLeft
                  ? Alignment.bottomRight
                  : Alignment.topLeft;
            });
          },
          child: const Text('Move'),
        ),
      ],
    );
  }
}

class _Box extends StatelessWidget {
  const _Box({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
      width: 50,
      height: 50,
    );
  }
}

Example

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me so that I can take time to read the issues, fix bugs, merge pull requests and add features to these packages.

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

You might also like...

A flutter plugin which provides Crop Widget for cropping images.

A flutter plugin which provides Crop Widget for cropping images.

A flutter plugin which provides Crop Widget for cropping images.

Jan 5, 2023

Customizable Flutter widget which syncronize ScrollView with PageView as tabs

Customizable Flutter widget which syncronize ScrollView with PageView as tabs

scrollable_list_tab_scroller Customizable Flutter widget which syncronize ScrollView with PageView as tabs. Create a custom page view as tabs which sy

Dec 21, 2022

A sliding up panel widget which can be used to show or hide content, beautiful and simple.

A sliding up panel widget which can be used to show or hide content, beautiful and simple.

flutter_sliding_up_panel A sliding up panel widget which can be used to show or hide content, beautiful and simple. demo Getting Started dependencies:

Dec 12, 2022

Global loading widget, which can be used through simple configuration.

Global loading widget, which can be used through simple configuration.

load Global loading widget, which can be used through simple configuration. Pure flutter library, not use native code. It is similar to OKToast in use

Nov 4, 2022

Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.

Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.

sticky_and_expandable_list Flutter implementation of sticky headers and expandable list.Support use it in a CustomScrollView. README i18n:中文说明 Feature

Nov 16, 2022

Flutter Color Picker Wheel - an easy to use widget which can be heavily customized

Flutter Color Picker Wheel  - an easy to use widget which can be heavily customized

Flutter Color Picker Wheel Flutter Color Picker Wheel is an easy to use widget which can be heavily customized. You can use the WheelColorPicker direc

Oct 4, 2022

Flutter package which helps you to implement Ticket Widget in your app.

Flutter package which helps you to implement Ticket Widget in your app.

✨ Ticket Widget Flutter package which helps you to implement Ticket Widget in your app. The source code is 100% Dart, and it is an updated null safe v

Dec 30, 2022

A Flutter widget which synchronize a ScrollView and a custom tab view

A Flutter widget which synchronize a ScrollView and a custom tab view

scrollable_list_tabview A Flutter widget which synchronize a ScrollView and a custom tab view. The main idea is to create a custom tab view synchroniz

Apr 12, 2022

A simple Flutter widget to add in the widget tree when you want to show nothing, with minimal impact on performance.

nil A simple widget to add in the widget tree when you want to show nothing, with minimal impact on performance. Why? Sometimes, according to a condit

Dec 22, 2022
Comments
  • [Widgets are swapped] : Using this with different types of widgets produces weird result.

    [Widgets are swapped] : Using this with different types of widgets produces weird result.

    Let me know if I am missing something, but when I try to move between two different types of widgets, the widgets to be rendered is swapped in the next transition.

    Top Widget
    Container(
              key: ValueKey(tile),
              child: LocalHero(
                tag: tile.text,
                child: GestureDetector(
                  onTap: () {
                    setState(() {
                      colTiles.add(tile);
                      rowTiles.remove(tile);
                    });
                  },
                  child: Container(
                    color: tile.color,
                    height: 60,
                    width: 60,
                    child: Padding(
                      padding: const EdgeInsets.all(16),
                      child: CircleAvatar(
                        backgroundColor: Colors.white70,
                        foregroundColor: Colors.black54,
                        child: Text(tile.text),
                      ),
                    ),
                  ),
                ),
              ),
            )
    
    Bottom Widget
    Container(
                      key: ValueKey(tile),
                      child: LocalHero(
                        tag: tile.text,
                        child: GestureDetector(
                          onTap: () {
                            setState(() {
                              rowTiles.add(tile);
                              colTiles.remove(tile);
                            });
                          },
                          child: Container(
                            width: 80,
                            height: 80,
                            color: tile.color,
                          ),
                        ),
                      ),
                    )
    

    So basically the top widget has text and the bottom doesn't.

    The issue is TopWidget is rendered in the bottom column in the next transition if the item was previously a part of the top row.

    Here is the code if you want to test it out yourself.

    opened by bimsina 1
  • I got a strange behavior on real devices Android versions 9, 10 with rendering Object with Animation

    I got a strange behavior on real devices Android versions 9, 10 with rendering Object with Animation

    Hi! I got a strange behavior on real devices Android versions 9, 10.

    Flutter 3.3.3 and higher.

    Object motion animation is missing.

    On emulators everything is fine. On Ios everything is fine. On a real device Android version 13 all is good.

    I have attached a video with an example of the problem.

    https://youtu.be/6BazKnSoMBk

    opened by vfxbro 0
  • Would be great to have a callback on animationEnded

    Would be great to have a callback on animationEnded

    Sometimes, I want to do stuff after the local heroes are done animating.

    Current flow is that I change the inflightbuilder to add False to an array, whenever a local hero starts animating, and to add True to the same array when the status is animationStatus == completed. Whenever the number of True == number of False, I do what I want to do next.

    Does it make sense for the LocalHeroController to provide a callback to do, I guess that would be way more efficient than a bunch of setState commands?

    opened by FrankDomburg 2
  • LocalHeroScope needed to use Local Hero

    LocalHeroScope needed to use Local Hero

    I noticed that I had to add a LocalHeroScope to my app, in order to make everything work.

    Does it make sense to integrate that into LocalHeroController? Would make for much simpler implementation right?

    Also, made a pull request, so that everything compiles neatly (at least for Android development) without warnings.

    opened by FrankDomburg 0
Owner
Romain Rastel
Flutter Developer
Romain Rastel
Custom-Position-Popup - Custom Position Popup For Flutter

Custom-Position-Popup before clone the GitHub repository please give a star on t

Blackshadow Software Ltd 11 Oct 17, 2022
Flutter package: Define a theme (colors, text styles etc.) as static const values which can be changed dynamically.

Flutter package: Define a theme (colors, text styles etc.) as static const values which can be changed dynamically. Also comes with useful extensions to create text styles by composition.

Marcelo Glasberg 21 Jan 2, 2023
A widget that imposes different constraints on its child than it gets from its parent

A widget that imposes different constraints on its child than it gets from its parent, possibly allowing the child to overflow the parent. Similar to `OverflowBox` except that the unconstrained width or height is sized to the intrinsic size of the child, instead of being assumed to be infinite, which allows IntrinsicSizeOverflowBox to be used in a `Scrollable` widget.

Ron Booth 3 Dec 7, 2022
A dice game made with Flutter and its Animation Widget

Jogo de dado feito com animação em flutter Esse projeto é um jogo de dado feito com Flutter e seus Widget de animação. Não foi necessário uso de pacot

Francis Santos 0 May 10, 2022
An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds

An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds. Based on the original idea by @shrouxm he

gskinner team 26 Dec 31, 2022
GetX demo Counter with full understanding of State Management, Route Management and SnackBar

GetX demo Counter with full understanding of State Management, Route Management and SnackBar

TAD 1 Apr 4, 2022
A package for flutter to use alert and toast within one line code.

easy_alert A package for flutter to use alert and toast within one line code. Getting Started Add easy_alert: to your pubspec.yaml, and run flutt

null 34 Jun 25, 2021
The SpannableGrid is a Flutter widget that allows its cells to span columns and rows and supports moving cells inside the grid.

Spannable Grid The SpannableGrid is a Flutter widget that allows its cells to span columns and rows and supports moving cells inside the grid. Feature

Evgeny Cherkasov 17 Nov 7, 2022
AdvFAB - An Advanced floating action button that expands itself to reveal its hidden widget

AdvFAB (More Than Just A Floating Action Button) AdvFAB is An Advanced floating action button that expands itself to reveal its hidden widget. It can

null 19 Nov 4, 2022
A Flutter widget that will give a Glitch Animation Effect to it's child widget.

GlitchEffect A Flutter widget that will give a Glitch Animation Effect to it's child widget. Installation Add the latest version of package to your pu

Sameer Singh 6 Nov 25, 2022