Skip to content

Material should have a non-animating constructor #45577

Closed

Description

@goderbauer

Currently, the Material widget animates all changes to any of its properties. For some use cases it would be cool to turn those implicit animations off (e.g. when the animation is actually driven from the outside, see https://github.com/flutter/packages/pull/30/files#r349369211).

Activity

  1. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Nov 25, 2019
  2. HansMuller commented on Jan 3, 2020

    @HansMuller
    Contributor

    A Material widget that does not implicitly animate properties could build a relatively simple widget tree. That would be helpful in cases where the app doesn't want the animation, or is doing it's own animation at a higher level.

  3. goderbauer commented on Jan 3, 2020

    @goderbauer
    MemberAuthor

    Workaround: You can currently achieve a non-animating material by setting its duration property to Duration.zero.

    However, as Hans pointed out, we could probably build a simpler widget tree in that case since setting the Duration to zero still builds all the implicit animation cruft.

  4. micimize commented on Jan 4, 2020

    @micimize
    Contributor

    One way we could expose this in a backwards-compatible way is by adding an animated (default true) that just toggles the use of _MaterialInterior:

        return widget.animated
            ? _MaterialInterior(
                curve: Curves.fastOutSlowIn,
                duration: widget.animationDuration,
                shape: shape,
                borderOnForeground: widget.borderOnForeground,
                clipBehavior: widget.clipBehavior,
                elevation: widget.elevation,
                color: backgroundColor,
                shadowColor: widget.shadowColor,
                child: contents,
              )
            : PhysicalShape(
                child: _ShapeBorderPaint(
                  child: contents,
                  shape: shape,
                  borderOnForeground: widget.borderOnForeground,
                ),
                clipper: ShapeBorderClipper(
                  shape: shape,
                  textDirection: Directionality.of(context),
                ),
                clipBehavior: widget.clipBehavior,
                elevation: widget.elevation,
                color: ElevationOverlay.applyOverlay(
                    context, backgroundColor, widget.elevation),
                shadowColor: widget.shadowColor,
              );

    Another option would be to make another widget MotionlessMaterial, which notably could be done in userland fairly easily

  5. Hixie commented on Mar 18, 2023

    @Hixie
    Contributor

    Another solution is just to set a Key on the widget when you replace it, that'll cause the old one to be thrown away and a new one created without animating.

    Given that there are numerous solutions, I'm going to close this bug.

  6. github-actions commented on Apr 1, 2023

    @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.

  7. locked as resolved and limited conversation to collaborators on Apr 1, 2023
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

    c: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions