Skip to content

AnimatedContainer throws Exception when animating height with easeOutBack curve. #37559

Closed

Description

@iliasbhal

Steps to Reproduce

  1. Create AnimatedContainer with height 25 and curve set to Curves.easeOutBack
  2. change State to Animate it to 0
  3. the Exception/Error is thrown.

While transitioning height with the easeOutBack curve, flutter throws an Exception because height becomes negative at some point during the animation.

The expected behavior would have been to "clamp" the height so it never goes below 0. or maybe behave like negative margins in CSS. idk 🤷‍♂

Source

    return AnimatedContainer(
      duration: Duration(milliseconds: 300),
      curve: Curves.easeOutQuint,
      height: containerHeight, // ex: it toggles between 25 and 0.
      alignment: Alignment.center,
      child: Text('some text',
        style: TextStyle(
            fontSize: 12,
            color: Colors.grey,
          ),
      ),
    )

Logs

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building
flutter: AnimatedContainer-[<'read-receit-text-bottom-6'>](duration: 400ms, centerLeft,
flutter: BoxConstraints(0.0<=w<=Infinity, h=1.0), margin: EdgeInsets(45.0, 0.0, 25.0, 0.0), dirty, state:
flutter: _AnimatedContainerState#4493e(ticker active, AlignmentGeometryTween(centerLeft → centerLeft),
flutter: BoxConstraintsTween(BoxConstraints(0.0<=w<=Infinity, h=25.0) → BoxConstraints(0.0<=w<=Infinity,
flutter: h=1.0)), margin: EdgeInsetsGeometryTween(EdgeInsets(45.0, 0.0, 25.0, 0.0) → EdgeInsets(45.0, 0.0,
flutter: 25.0, 0.0)))):
flutter: BoxConstraints has a negative minimum height.
flutter: The offending constraints were:
flutter:   BoxConstraints(0.0<=w<=Infinity, h=-0.3; NOT NORMALIZED)
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError 
package:flutter/…/rendering/box.dart:507
flutter: #1      BoxConstraints.debugAssertIsValid.<anonymous closure> 
package:flutter/…/rendering/box.dart:537
flutter: #2      BoxConstraints.debugAssertIsValid 
package:flutter/…/rendering/box.dart:554
flutter: #3      new Container 
package:flutter/…/widgets/container.dart:270
flutter: #4      _AnimatedContainerState.build 
package:flutter/…/widgets/implicit_animations.dart:668
flutter: #5      StatefulElement.build 
package:flutter/…/widgets/framework.dart:4012
flutter: #6      ComponentElement.performRebuild 
package:flutter/…/widgets/framework.dart:3924
flutter: #7      Element.rebuild 
package:flutter/…/widgets/framework.dart:3721
flutter: #8      BuildOwner.buildScope 
package:flutter/…/widgets/framework.dart:2340
flutter: #9      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame 
package:flutter/…/widgets/binding.dart:700
flutter: #10     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback 
package:flutter/…/rendering/binding.dart:285
flutter: #11     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback 
package:flutter/…/scheduler/binding.dart:1016
flutter: #12     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame 
package:flutter/…/scheduler/binding.dart:958
flutter: #13     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame 
package:flutter/…/scheduler/binding.dart:874
flutter: #17     _invoke  (dart:ui/hooks.dart:236:10)
flutter: #18     _drawFrame  (dart:ui/hooks.dart:194:3)
flutter: (elided 3 frames from package dart:async)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: BoxConstraints has a negative minimum height.

flutter analyze

// nothing except few linting logs.

flutter doctor -v

[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.5 18F132, locale
    en-CA)
    • Flutter version 1.7.8+hotfix.4 at /Users/iliasbhallil/flutter
    • Framework revision 20e59316b8 (2 weeks ago), 2019-07-18 20:04:33 -0700
    • Engine revision fee001c93f
    • Dart version 2.4.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/iliasbhallil/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/iliasbhallil/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.3, Build version 10G8
    • CocoaPods version 1.6.0.beta.2

[✓] iOS tools - develop for iOS devices
    • ios-deploy 1.9.4

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 37.1.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.36.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.3.0

[✓] Connected device (1 available)
    • iPhone Xʀ • 80A92D26-45F4-400A-95DF-89CA1CDA58A7 • ios •
      com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Sep 19, 2019
  2. TahaTesser commented on Feb 21, 2020

    @TahaTesser
    Contributor

    Hi @iliasbhal
    After testing this on Flutter 1.12.13+hotfix.8 • channel stable, it couldn't be reproduced.
    Are you still experiencing this issue?
    Thank you

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 21, 2020
  4. VladyslavBondarenko commented on Mar 16, 2020

    @VladyslavBondarenko

    a bit modified code from https://flutter.dev/docs/cookbook/animation/animated-container

    this code sample
    import 'dart:math';
    
    import 'package:flutter/material.dart';
    
    void main() => runApp(AnimatedContainerApp());
    
    class AnimatedContainerApp extends StatefulWidget {
      @override
      _AnimatedContainerAppState createState() => _AnimatedContainerAppState();
    }
    
    class _AnimatedContainerAppState extends State<AnimatedContainerApp> {
      // Define the various properties with default values. Update these properties
      // when the user taps a FloatingActionButton.
      double _width = 50;
      double _height = 50;
      Color _color = Colors.green;
      BorderRadiusGeometry _borderRadius = BorderRadius.circular(8);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text('AnimatedContainer Demo'),
            ),
            body: Center(
              child: AnimatedContainer(
                // Use the properties stored in the State class.
                width: _width,
                height: _height,
                decoration: BoxDecoration(
                  color: _color,
                  borderRadius: _borderRadius,
                ),
                // Define how long the animation should take.
                duration: Duration(seconds: 1),
                // Provide an optional curve to make the animation feel smoother.
                curve: Curves.easeOutBack,
              ),
            ),
            floatingActionButton: FloatingActionButton(
              child: Icon(Icons.play_arrow),
              // When the user taps the button
              onPressed: () {
                // Use setState to rebuild the widget with new values.
                setState(() {
                  // Create a random number generator.
                  final random = Random();
    
                  // Generate a random width and height.
                  _width = random.nextInt(300).toDouble();
                  _height = random.nextInt(1).toDouble();
    
                  // Generate a random color.
                  _color = Color.fromRGBO(
                    random.nextInt(256),
                    random.nextInt(256),
                    random.nextInt(256),
                    1,
                  );
    
                  // Generate a random border radius.
                  _borderRadius =
                      BorderRadius.circular(random.nextInt(100).toDouble());
                });
              },
            ),
          ),
        );
      }
    }
    

    throws the exception with easeOutBack

    (flutter version v1.15.22-pre.33)

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 16, 2020
  6. markusaksli-nc commented on Aug 11, 2020

    @markusaksli-nc
    Contributor

    This happens because easeOutBack, like a lot of other Curves, overshoots its bounds.

    This curve is similar to Curves.elasticOut in that it overshoots its bounds before reaching its end.

    This means when shrinking, the animation overshoots the height bound (0) and goes negative for a bit. This behavior should be expected and can be avoided with a lot of other curves that do not overshoot their bounds. Not even sure what the expected behavior for an animation overshooting a size of 0 should be. As far as I know, there is no official documentation about any clamped dimensions in Flutter.

    Leaving this open since the error message or the documentation for overshooting curves can be improved to clarify this case.

  7. added
    P2Important issues not at the top of the work list
    on Jan 24, 2023
  8. github-actions commented on Aug 29, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsa: error messageError messages from the Flutter frameworkd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions