Package selection guidance compiled from public package information, community data, and project usage.
A lightweight Dart utility package that simplifies the creation of Matrix4 transformations for 2D and 3D graphics in Flutter. It provides intuitive methods to build transformation matrices for use with widgets like Container via the transform parameter, enabling precise control over rotation, scaling, translation, and skewing. Ideal for animations, custom layouts, and interactive UI elements requiring advanced transforms. The package is platform-agnostic and integrates seamlessly into Flutter projects.
Use cases
Animating UI elements with complex transforms
Creating custom 2D/3D layouts
Building interactive gesture-based interfaces
Implementing camera or view rotations
Designing scalable game or visualization components
Key features
Simple, chainable matrix construction
Supports rotation, scale, translation, and skew
Intuitive API for common transform operations
Works directly with Container's transform property
Lightweight and dependency-free
Suitable for
Flutter developers needing precise matrix control
UI designers working on animated or interactive layouts
Game or visualization app creators
Beginners learning about 3D transforms in Flutter
Considerations
Not intended for heavy mathematical computations
Requires understanding of Matrix4 concepts
Limited to transform-related utilities
No built-in animation support
Best used alongside animation controllers for dynamic effects
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
matrix4_transform
Have you noticed the transform parameter in the Container and Transform widgets,
which lets you move, rotate, resize, and flip?
This package provides a helper math class that makes it easy to create Matrix4
transformations.
Example:
// Rotates the Container 45 degrees and then
// translates 25 pixels to the right.
Container(
transform:
Matrix4Transform()
.rotateDegrees(45, origin: Offset(25, 25))
.translate(x: 25)
.matrix4,
child: ...
);
To see it in action, run the example in
the example tab.
How to use it
Matrix4Transform is immutable (in contrast, Matrix4 is mutable).
First create a Matrix4Transform:
Matrix4Transform();
Then call the methods to transform it. For example:
A Matrix4TransformTween is provided in this package, and can be used in animations.
Animate it
A Matrix4Transform can be used to animate:
AlignPositioned or AnimatedAlignPositioned widgets from
the AlignPositioned package,
that accept a Matrix4Transform directly. The center of rotation/scale can be defined
by their alignment parameter.
Any widget that accepts a Matrix4 transformation parameter, like Container,
or AnimatedContainer. Note: Since Matrix4Tween will not animate linearly as you'd
expect, it's possible that the intermediary transformations will be "strange", although
the start and end should be correct.
Special thanks to Martin Kamleithner and Simon Lightfoot.