animated_size_and_fade 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

pub package

animated_size_and_fade #

This allows you to:

  1. Do a fade and size transition between two widgets.
  2. Show and hide a widget, by resizing it vertically while fading.

Fade and Size #

The AnimatedSizeAndFade widget does a fade and size transition between a "new" widget and an "old" widget previously set as a child. The "old" and the "new" children must have the same width, but can have different heights, and you don't need to know their sizes in advance.

You can also define a duration and curve for both the fade and the size, separately.

Important: If the "new" child is the same widget type as the "old" child, but with different parameters, then [AnimatedSizeAndFade] will NOT do a transition between them, since as far as the framework is concerned, they are the same widget, and the existing widget can be updated with the new parameters. To force the transition to occur, set a [Key] (typically a [ValueKey] taking any widget data that would change the visual appearance of the widget) on each child widget that you wish to be considered unique.


bool toggle=true;
Widget widget1 = ...;
Widget widget2 = ...;

   vsync: this, 
   child: toggle ? widget1 : widget2

Show and Hide #

The AnimatedSizeAndFade.toggle constructor may be used to show/hide a widget, by resizing it vertically while fading.


bool toggle=true;
Widget widget = ...;    

   vsync: this, 
   show: toggle,
   child: widget,

How does it compare to other similar widgets? #

  • With AnimatedCrossFade you must keep both the firstChild and secondChild, which is not necessary with AnimatedSizeAndFade.

  • With AnimatedSwitcher you may simply change its child, but then it only animates the fade, not the size.

  • AnimatedContainer also doesn't work unless you know the size of the children in advance.

Note: See the StackOverflow question that prompted this widget development.

The Flutter packages I've authored:

Marcelo Glasberg:

[1.0.5] - 2019/10/18

  • Toggle constructor (to show/hide).

[1.0.3] - 2019/06/18

  • Added example.

[1.0.0] - 2019/06/17

  • Initial.


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

void main() {

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
  bool toggle;

  void initState() {
    toggle = false;

  Widget build(BuildContext context) {
    var toggleButton = Padding(
      padding: const EdgeInsets.all(8.0),
      child: MaterialButton(
        child: const Text("Toggle"),
        color: Colors.grey,
        onPressed: () {
          setState(() {
            toggle = !toggle;

    var widget1 = Container(
      key: ValueKey("first"),
      width: 200.0,
      child: const Text(
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt "
            "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
            "ullamco laboris nisi ut aliquip ex ea commodo consequat.",

    var widget2 = Container(
      key: ValueKey("second"),
      width: 200.0,
      child: const Text(
        "I am ready for my closeup.",

    return MaterialApp(
      home: Material(
        child: Row(
          children: <Widget>[
            Container(height: 100.0),
              children: <Widget>[
                const Text("Some text above."),
                  vsync: this,
                  child: toggle ? widget1 : widget2,
                  fadeDuration: const Duration(milliseconds: 300),
                  sizeDuration: const Duration(milliseconds: 600),
                const Text("Some text below."),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  animated_size_and_fade: ^1.0.5

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:animated_size_and_fade/animated_size_and_fade.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies