패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.0.1

matrix4_transform

Matrix4 변환을 쉽게 만들 수 있도록 도와주는 보조 수학 클래스로, Container의 transform 매개변수 및 기타 곳에서 사용할 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
7.3만
좋아요
185
Pub 점수
150

패키지 설치

flutter pub add matrix4_transform

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Flutter에서 2D 및 3D 그래픽의 Matrix4 변환을 생성하는 것을 단순화하는 가벼운 Dart 유틸리티 패키지입니다. Container와 같은 위젯에 transform 매개변수를 사용하여 회전, 스케일링, 이동, 기울기 등을 정밀하게 제어할 수 있도록 직관적인 메서드를 제공합니다. 애니메이션, 커스텀 레이아웃, 고급 변환이 필요한 인터랙티브 UI 요소에 적합합니다. 패키지는 플랫폼에 관계없이 사용 가능하며 Flutter 프로젝트에 원활하게 통합됩니다.

사용 사례

  • 복잡한 변환을 사용하여 UI 요소 애니메이션화
  • 사용자 정의 2D/3D 레이아웃 만들기
  • 상호작용하는 제스처 기반 인터페이스 구축
  • 카메라 또는 뷰 회전 구현
  • 확장 가능한 게임 또는 시각화 구성 요소 설계

주요 기능

  • 간단하고 체인 가능한 행렬 생성
  • 회전, 스케일링, 이동 및 기울기 지원
  • 일반적인 변환 작업을 위한 직관적인 API
  • Container의 transform 속성과 직접 작동합니다
  • 경량이며 종속성 없음

적합한 대상

  • 정밀한 행렬 제어가 필요한 플러터 개발자
  • 애니메이션 또는 인터랙티브 레이아웃을 작업하는 UI 디자이너
  • 게임 또는 시각화 앱 제작자
  • 플러터에서 3D 변환을 배우는 초보자

고려 사항

  • 중요한 수학 계산을 위한 것이 아님
  • Matrix4 개념에 대한 이해가 필요합니다
  • 변형 관련 유틸리티에 한정
  • 내장 애니메이션 지원 없음
  • 동적 효과를 위해 애니메이션 컨트롤러와 함께 사용하는 것이 가장 좋습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

pub package

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:

Matrix4Transform()
   .scale(1.5)
   .upRight(35)
   .rotate(pi/2);

In the end, call matrix4:

Matrix4 myMatrix 
   = Matrix4Transform()
     .scale(1.5)
     .upRight(35)
     .rotate(pi/2)
     .matrix4;                        

Note: The transformations will be applied in order, and their order may change the end result.

If you already have a matrix4 and want to further transform it, you can use the from constructor:

Matrix4 myMatrix = ...;

var myTransform = Matrix4Transform.from(myMatrix);

Methods you can use

  • rotate(double angleRadians, {Offset origin})
  • rotateDegrees(double angleDegrees, {Offset origin})
  • rotateByCenterDegrees(double angleDegrees, Size size)
  • rotateByCenter(_toRadians(angleDegrees), size)
  • translate({double x = 0, double y = 0})
  • translateOriginalCoordinates({double x = 0, double y = 0})
  • scale(double factor, {Offset origin})
  • scaleBy({double x = 1, double y = 1, Offset origin})
  • scaleHorizontally(double factor)
  • scaleVertically(double factor)
  • translateOffset(Offset offset)
  • up(double distance)
  • down(double distance)
  • right(double distance)
  • left(double distance)
  • direction(double directionRadians, double distance)
  • directionDegrees(double directionDegrees, double distance)
  • upRight(double distance)
  • upLeft(double distance)
  • downRight(double distance)
  • downLeft(double distance)
  • flipDiagonally({Offset origin})
  • flipHorizontally({Offset origin})
  • flipVertically({Offset origin})

And, of course:

  • Matrix4 toMatrix4

Tween

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.


By Marcelo Glasberg

glasberg.dev
github.com/marcglasberg
linkedin.com/in/marcglasberg/
twitter.com/glasbergmarcelo
stackoverflow.com/users/3411681/marcg
medium.com/@marcglasberg

My article in the official Flutter documentation:

The Flutter packages I've authored:

My Medium Articles:

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트