1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using uiwidgets ;
5
+ using Unity . UIWidgets . animation ;
6
+ using Unity . UIWidgets . engine ;
7
+ using Unity . UIWidgets . foundation ;
8
+ using Unity . UIWidgets . material ;
9
+ using Unity . UIWidgets . painting ;
10
+ using Unity . UIWidgets . rendering ;
11
+ using Unity . UIWidgets . ui ;
12
+ using Unity . UIWidgets . widgets ;
13
+ using ui_ = Unity . UIWidgets . widgets . ui_ ;
14
+
15
+ namespace UIWidgetsSample
16
+ {
17
+ public class FlowSample : UIWidgetsPanel
18
+ {
19
+ protected override void main ( )
20
+ {
21
+ ui_ . runApp ( new MaterialApp (
22
+ showPerformanceOverlay : false ,
23
+ home : new FlowDemo ( ) ) ) ;
24
+ }
25
+
26
+ protected new void OnEnable ( )
27
+ {
28
+ base . OnEnable ( ) ;
29
+ }
30
+
31
+ protected override void onEnable ( )
32
+ {
33
+ AddFont ( "Material Icons" , new List < string > { "MaterialIcons-Regular.ttf" } , new List < int > { 0 } ) ;
34
+ }
35
+ }
36
+
37
+ public class FlowDemo : StatefulWidget
38
+ {
39
+ public FlowDemo ( Key key = null ) : base ( key )
40
+ {
41
+ }
42
+
43
+ public override State createState ( )
44
+ {
45
+ return new _FlowDemoState ( ) ;
46
+ }
47
+ }
48
+
49
+ class FlowDemoDelegate : FlowDelegate
50
+ {
51
+ public FlowDemoDelegate ( Animation < float > myAnimation ) : base ( repaint : myAnimation )
52
+ {
53
+ this . myAnimation = myAnimation ;
54
+ }
55
+
56
+ Animation < float > myAnimation ;
57
+
58
+ public override bool shouldRepaint ( FlowDelegate oldDelegate )
59
+ {
60
+ var _oldDelegate = oldDelegate as FlowDemoDelegate ;
61
+ return myAnimation != _oldDelegate ? . myAnimation ;
62
+ }
63
+
64
+ public override void paintChildren ( FlowPaintingContext context )
65
+ {
66
+ for ( int i = context . childCount - 1 ; i >= 0 ; i -- )
67
+ {
68
+ float dx = ( context . getChildSize ( i ) . height + 10 ) * i ;
69
+ context . paintChild (
70
+ i ,
71
+ transform : Matrix4 . translationValues ( 0 , dx * myAnimation . value + 10 , 0 )
72
+ ) ;
73
+ }
74
+ }
75
+
76
+ public override Size getSize ( BoxConstraints constraints )
77
+ {
78
+ return new Size ( 70.0f , float . PositiveInfinity ) ;
79
+ }
80
+
81
+
82
+ public override BoxConstraints getConstraintsForChild ( int i , BoxConstraints constraints )
83
+ {
84
+ return i == 0 ? constraints : BoxConstraints . tight ( new Size ( 50.0f , 50.0f ) ) ;
85
+ }
86
+ }
87
+
88
+ public class _FlowDemoState : SingleTickerProviderStateMixin < FlowDemo >
89
+ {
90
+ private AnimationController _myAnimation ;
91
+
92
+ List < IconData > _icons = new List < IconData >
93
+ {
94
+ Icons . menu ,
95
+ Icons . email ,
96
+ Icons . settings ,
97
+ Icons . notifications ,
98
+ Icons . person ,
99
+ Icons . wifi
100
+ } ;
101
+
102
+ public override void initState ( )
103
+ {
104
+ base . initState ( ) ;
105
+
106
+ _myAnimation = new AnimationController (
107
+ duration : new TimeSpan ( 0 , 0 , 0 , 1 ) ,
108
+ vsync : this
109
+ ) ;
110
+ }
111
+
112
+ Widget _buildItem ( IconData icon )
113
+ {
114
+ return new Padding (
115
+ padding : EdgeInsets . symmetric ( horizontal : 10.0f ) ,
116
+ child : new RawMaterialButton (
117
+ fillColor : Colors . cyan ,
118
+ shape : new CircleBorder ( ) ,
119
+ constraints : BoxConstraints . tight ( Size . square ( 50.0f ) ) ,
120
+ onPressed : ( ) =>
121
+ {
122
+ if ( _myAnimation . status == AnimationStatus . completed )
123
+ {
124
+ _myAnimation . reverse ( ) ;
125
+ }
126
+ else
127
+ {
128
+ _myAnimation . forward ( ) ;
129
+ }
130
+ } ,
131
+ child : new Icon (
132
+ icon ,
133
+ color : Colors . white ,
134
+ size : 30.0f
135
+ )
136
+ )
137
+ ) ;
138
+ }
139
+
140
+ public override Widget build ( BuildContext context )
141
+ {
142
+ return new Scaffold (
143
+ appBar : new AppBar (
144
+ automaticallyImplyLeading : false ,
145
+ title : new Text ( "Flutter Flow Widget Demo" ) ,
146
+ backgroundColor : Colors . cyan
147
+ ) ,
148
+ body : new Stack (
149
+ children : new List < Widget >
150
+ {
151
+ new Container ( color : Colors . grey [ 200 ] ) ,
152
+ new Flow (
153
+ _delegate : new FlowDemoDelegate ( myAnimation : _myAnimation ) ,
154
+ children : _icons
155
+ . Select ( ( IconData icon ) => _buildItem ( icon ) ) . ToList ( )
156
+ ) ,
157
+ }
158
+ )
159
+ ) ;
160
+ }
161
+ }
162
+ }
0 commit comments