@@ -10,30 +10,51 @@ class WidgetViewer extends StatefulWidget {
10
10
class _WidgetViewerState extends State <WidgetViewer > {
11
11
double _horizontalRotation = 0 ;
12
12
double _verticalRotation = 0 ;
13
+ double _zRotation = 0 ;
14
+ double _perspective = 0 ;
13
15
double _zoom = 1 ;
14
16
17
+ final List <Color > colors = [Colors .green, Colors .yellow, Colors .purple];
18
+
15
19
@override
16
20
Widget build (BuildContext context) {
17
21
return Scaffold (
18
- appBar: AppBar (title: Text ('3D Widget Viewer' )),
22
+ appBar: AppBar (title: Text ('3D Stacked Widget Viewer' )),
19
23
body: Column (
20
24
children: [
21
25
Expanded (
22
26
child: Center (
23
27
child: Transform (
28
+ // setEntry(0, 3, x): Translates along the X-axis
29
+ // setEntry(1, 3, y): Translates along the Y-axis
30
+ // setEntry(2, 3, z): Translates along the Z-axis
24
31
transform: Matrix4 .identity ()
25
- ..setEntry (3 , 2 , 0.001 ) // perspective
26
- ..rotateY (_horizontalRotation * pi / 180 )
27
- ..rotateX (_verticalRotation * pi / 180 )
32
+ ..setEntry (3 , 2 , 0.0003512553609721081 ) // perspectivez
33
+ // ..setEntry(3, 1, _perspective) // y
34
+ // ..setEntry(3, 0, _perspective) //x
35
+ ..rotateY (323 * pi / 180 ) // horixontal
36
+ ..rotateX (355 * pi / 180 ) // vertical
37
+ ..rotateZ (6 * pi / 180 ) //z : 32
28
38
..scale (_zoom),
29
39
alignment: Alignment .center,
30
- child: Container (
31
- width: 200 ,
32
- height: 200 ,
33
- color: Colors .blue,
34
- child: Center (
35
- child: Text ('2D Widget' ,
36
- style: TextStyle (color: Colors .white))),
40
+ child: Stack (
41
+ children: List .generate (colors.length, (index) {
42
+ return Transform (
43
+ transform: Matrix4 .identity ()
44
+ ..translate (0.0 , 0.0 , - index * 50.0 ), // -index * 50.0
45
+ child: Container (
46
+ width: 200 ,
47
+ height: 200 ,
48
+ color: colors[index],
49
+ child: Center (
50
+ child: Text (
51
+ 'Layer ${index + 1 }' ,
52
+ style: TextStyle (color: Colors .white),
53
+ ),
54
+ ),
55
+ ),
56
+ );
57
+ }),
37
58
),
38
59
),
39
60
),
@@ -56,6 +77,21 @@ class _WidgetViewerState extends State<WidgetViewer> {
56
77
label:
57
78
'Vertical Rotation: ${_verticalRotation .toStringAsFixed (0 )}°' ,
58
79
),
80
+ _buildSlider (
81
+ value: _zRotation,
82
+ onChanged: (value) => setState (() => _zRotation = value),
83
+ label: 'Z Rotation: ${_zRotation .toStringAsFixed (0 )}°' ,
84
+ ),
85
+ _buildSlider (
86
+ value: _perspective,
87
+ min: - 0.1 ,
88
+ max: 0.1 ,
89
+ onChanged: (value) => setState (() {
90
+ _perspective = value;
91
+ print ("Perspective, value: $_perspective " );
92
+ }),
93
+ label: 'Perspective: ${_perspective .toStringAsFixed (0 )}°' ,
94
+ ),
59
95
_buildSlider (
60
96
value: _zoom,
61
97
min: 0.5 ,
0 commit comments