Skip to content

Transform.rotate is super slow #24627

@arsen

Description

@arsen

I'm implementing a card swiping tinder like ui. Cards are being moved during onPanUpdate (within GestureDetector).
When applying just regular Transform.translate it is super smooth, but with when I apply also Transform.rotate it is missing a lot of frames (even on iPhone X).

This is the sample code:

class MemberCard extends StatelessWidget {
  final double width;
  final double height;
  final String photo;
  final double rotation;
  final Offset offset;
  final double scale;
  final bool dropShadow;

  MemberCard({
    this.width,
    this.height,
    this.photo,
    this.rotation = 0.0,
    this.offset = const Offset(0.0, 0.0),
    this.scale = 1.0,
    this.dropShadow = false,
  });

  @override
  Widget build(BuildContext context) {
    double angle = rotation * (math.pi / 180.0);
    var matrix = Matrix4.translationValues(offset.dx, offset.dy, 0.0);
    if (scale != 1.0) {
      matrix..scale(scale);
    }
    if (rotation != 0.0) {
      matrix.rotateZ(angle);
    }

    return Transform(
      alignment: Alignment.center,
      transform: matrix,
      child: Stack(
        children: <Widget>[
          RepaintBoundary(
            child: Container(
              width: width,
              height: height,
              decoration: BoxDecoration(
                boxShadow: dropShadow
                    ? [
                        BoxShadow(
                            color: Colors.black.withOpacity(0.4),
                            blurRadius: 5.0,
                            offset: Offset(0.0, 1.0))
                      ]
                    : [],
                borderRadius: BorderRadius.all(Radius.circular(10.0)),
                color: Colors.white,
                // image: DecorationImage(
                //   image: NetworkImage(photo),
                //   fit: BoxFit.cover,
                // ),
              ),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(10.0),
                child: Image.network(
                  photo,
                  fit: BoxFit.cover,
                  filterQuality: FilterQuality.none,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions