ZWidget는 어떤 위젯도 가상 3D 버전으로 변환할 수 있는 Flutter 패키지로, 부드럽고 직관적인 3D 효과 애니메이션을 가능하게 합니다. 깊이와 원근감 효과를 적용함으로써 복잡한 3D 렌더링 없이도 시각적 몰입감을 향상시킵니다. 카드, 버튼 또는 컨테이너와 같이 동적 깊이 반응을 갖는 몰입형 UI 요소를 만들기에 적합합니다. 이 패키지는 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼을 지원하며 장치 간 일관된 동작을 보장합니다.
사용 사례
애니메이션 3D 카드 만들기
버튼 상호작용 향상
몰입형 UI 컴포넌트 구축
정적 위젯에 깊이 추가하기
상호작용형 제품 미리보기 설계
애니메이션 레이아웃 전환
주요 기능
가상 3D 변환
깊이 기반의 부드러운 애니메이션
크로스 플랫폼 호환성
기존 위젯과의 간편한 통합
사용자 정의 가능한 시점 및 기울기
터치 및 제스처 입력을 지원합니다
적합한 대상
시각적 깊이를 추구하는 UI 디자이너
인터랙티브 프로토타입을 구축하는 개발자
매력적인 마이크로 상호작용을 필요로 하는 앱
다중 플랫폼을 대상으로 하는 프로젝트
창의적인 디지털 경험
고려 사항
저사양 기기에서의 성능 영향
제한된 진짜 3D 기하학
애니메이션 매개변수를 신중하게 조정해야 합니다
복잡한 3D 장면에 적합하지 않습니다
빌드 크기를 약간 증가시킬 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
ZWidget creates a 3D-like visual by stacking widgets one above the other and transforming them adequately.
Tilt your widgets and simulate 3D easily.
Here are a few examples with Text, FlutterLogo, Ìmage, Icon and CustomPaint:
You can also animate them:
The example project includes these demos and a few more.
Usage
ZWidget includes several constructors depending on the direction where you want your perspective effect to be.
ZWidget.backwards(), ZWidget.forwards() and ZWidget.bothDirections()
You must define at least the midChild, which is the base Widget that will be displayed.
Depending on the direction you want the perspective to take place, you may also define the extremities and the widget to display between them and the middle child.
Here is a full example for ZWidget.bothDirections():
ZWidget.bothDirections(
// middle layer
midChild: Container(
width: 60,
height: 60,
color: Colors.blue,
),
midToBotChild: Container(
width: 60,
height: 60,
color: Colors.blueGrey,
),
// layers between mid and top child
midToTopChild: Container(
width: 60,
height: 60,
color: Colors.lightBlue,
),
// layer at the bottom of the Stack
botChild: Container(
width: 60,
height: 60,
color: Colors.grey,
),
// layer at the top of the Stack
topChild: Container(
width: 60,
height: 60,
color: Colors.lightBlueAccent,
),
// rotation around X axis
rotationX: pi / 3,
// rotation around Y axis
rotationY: -pi / 4,
// Number of layers. Always odd (increased if even)
layers: 5,
// Space between layers
depth: 32,
)
ZWidget.backwards() and ZWidget.forwards() are similar but they provide only the children parameters adequate to their direction.
The layers of a ZWidget are visibles in the picture below:
There is always an odd number of layers. If you define an even number, it will be increased to be an odd number. Increase depth to increase their spacing.
ZDirection can be forward, backward or both.
Mid layer is the midChild. Depending on the ZDirection, other layers are displayed above or below the midChild.
You can define the botChild for the child at the bottom of the Stack and topChild for the one at the top.
You can also define Widgets between these extremities and midChild with midToTopChild and midToBotChild.
Use the alignment property to set the Transform origin.
To effectively see the 3D effect, you must define a rotation to the ZWidget using rotationX and rotationY.
ZWidget.builder()
In case you would like to control which Widget is displayed at each layer, you may use Widget.builder().
It can be used to make a gradient effect for instance.
Here are a few examples:
ZWidget()
While the base ZWidget constructor works, it may lead newcomers to define parameters that are not needed.
Therefore, it is now deprecated and you should use the other constructors instead.
Performance considerations
If ZWidget has 11 layers, it means that 11 Widgets will be drawn. Try to limit the complexity of widgets used at each layer.
For instance, an opaque Image could use simple Containers to simulate a 3D effect:
// The builder function used to build each layerfinalWidgetFunction(int) builder;
// Space between layersfinaldouble depth;
// Perspective directionfinalZDirection direction;
// Rotation around X axisfinaldouble rotationX;
// Rotation around Y axisfinaldouble rotationY;
// Number of layers. Always odd (increased if set even)finalint layers;
// Experimental, used to reverse the X and Y rotationsfinalbool reverse;
// Shows a pink border representing the size taken by this `ZWidget`.// Painting may go beyond that border.finalbool debug;
// The bigger the perspective, the more part of the widget will seem to be far away.finaldouble perspective;
// Transform originfinalAlignment? alignment;
// A fade effect (experimental)finalbool fade;
ZWidget size
Depending on the transformations and the 3D effect your want to achieve, your widget might be drawn beyond its limits.
The debug parameter shows a pink border around your ZWidget which indicates its layout size in the widget tree but the painting may go beyond that border.
That's because the Transform that we use doesn't change the base size of the widget, it just changes how it is rendered. The layout remains the same, but the painting can change a lot. See the Transformdocumentation for more infos.
You might want to cut it to fit in the border with a ClipRect for instance.
How does it work?
ZWidget fills a Stack with layers Widgets returned by a builder function.
These are then transformed to make the 3D effect.
This transformations is done using a Transform widget and a Matrix4. If you'd like to do something similar but not with Widget, you can use the top-level function zMatrix4().
zMatrix4
This method returns a Matrix4 used to perform 3D transformations.
You can use it on anything accepting a Matrix4 (Widget, Canvas, Path, ...).