1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_curve_visualizer/views/widgets/screen_mode.dart' ;
3
3
import 'package:flutter_curve_visualizer/utils/curves_enum.dart' ;
4
- import 'package:flutter_curve_visualizer/utils/extension/string.dart' ;
5
- import 'package:flutter_curve_visualizer/views/widgets/animated_box/animated_box_widget.dart' ;
6
4
import 'package:flutter_curve_visualizer/views/widgets/appbar.dart' ;
7
5
import 'package:flutter_curve_visualizer/views/widgets/dropdown_menu.dart' ;
8
6
import 'package:flutter_curve_visualizer/views/widgets/graph/graph_widget.dart' ;
7
+ import 'widgets/animated_box/animated_boxes.dart' ;
9
8
import 'widgets/code_block.dart' ;
10
9
11
10
class HomePage extends StatefulWidget {
@@ -70,6 +69,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
70
69
}
71
70
72
71
void updateCurve (CurvesEnum curve) {
72
+ if (curve == selectedCurve) return ;
73
+
73
74
setState (() {
74
75
selectedCurve = curve;
75
76
curveAnimation.curve = curve.curve;
@@ -115,11 +116,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
115
116
Widget build (BuildContext context) {
116
117
final screenMode = ScreenModeWidget .of (context);
117
118
118
- final double spacing = switch (screenMode) {
119
- ScreenMode .mobile => 20 ,
120
- ScreenMode .tablet => 30 ,
121
- ScreenMode .web => 30 ,
122
- };
119
+ final double spacing = screenMode.spacing;
123
120
124
121
final animationWidget = Column (
125
122
children: [
@@ -130,34 +127,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
130
127
),
131
128
132
129
// Box Animations
133
- SizedBox (
134
- width: MediaQuery .of (context).size.width /
135
- (screenMode.isMobileOrTablet ? 1 : 3 ),
136
- child: Wrap (
137
- spacing: spacing / 2 ,
138
- runSpacing: spacing / 2 ,
139
- runAlignment: WrapAlignment .center,
140
- alignment: WrapAlignment .center,
141
- children: AnimationType .values.map (
142
- (animationType) {
143
- return Column (
144
- mainAxisAlignment: MainAxisAlignment .start,
145
- spacing: 8.0 ,
146
- children: [
147
- Text (animationType.name.capitalizeFirst ()),
148
- SizedBox .square (
149
- dimension: 100 ,
150
- child: AnimatedBoxWidget (
151
- animationType: animationType,
152
- animation: curveAnimation,
153
- ),
154
- ),
155
- ],
156
- );
157
- },
158
- ).toList (),
159
- ),
160
- ),
130
+ AnimationBoxes (curveAnimation: curveAnimation),
161
131
],
162
132
);
163
133
@@ -167,31 +137,45 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
167
137
),
168
138
child: Column (
169
139
mainAxisSize: MainAxisSize .min,
140
+ mainAxisAlignment: MainAxisAlignment .end,
170
141
spacing: spacing,
171
142
children: [
172
143
// Code block
173
144
CodeBlock (curve: selectedCurve),
174
145
175
- // Curve category
176
- DropdownMenuWidget <String >(
177
- title: "Category" ,
178
- value: selectedCategory,
179
- items: CurvesEnum .list.keys.toList (),
180
- onChanged: updateCategory,
181
- ),
146
+ // Curve selector
147
+ Row (
148
+ spacing: 10 ,
149
+ mainAxisSize: MainAxisSize .min,
150
+ mainAxisAlignment: MainAxisAlignment .start,
151
+ children: [
152
+ // Curve category
153
+ Flexible (
154
+ child: DropdownMenuWidget <String >(
155
+ title: "Category" ,
156
+ value: selectedCategory,
157
+ items: CurvesEnum .list.keys.toList (),
158
+ onChanged: updateCategory,
159
+ ),
160
+ ),
182
161
183
- // Curve type
184
- DropdownMenuWidget <CurvesEnum >(
185
- title: "Type" ,
186
- value: selectedCurve,
187
- items: CurvesEnum .list[selectedCategory]! ..toList (),
188
- onChanged: (value) => updateCurve (value! ),
189
- childBuilder: (context, value, textStyle) {
190
- return Text (value.name.toString (), style: textStyle);
191
- },
162
+ // Curve type
163
+ Flexible (
164
+ flex: 2 ,
165
+ child: DropdownMenuWidget <CurvesEnum >(
166
+ title: "Type" ,
167
+ value: selectedCurve,
168
+ items: CurvesEnum .list[selectedCategory]! ..toList (),
169
+ onChanged: (value) => updateCurve (value! ),
170
+ childBuilder: (context, value, textStyle) {
171
+ return Text (value.name.toString (), style: textStyle);
172
+ },
173
+ ),
174
+ ),
175
+ ],
192
176
),
193
177
194
- // Curve type
178
+ // Animation time
195
179
Container (
196
180
padding: EdgeInsets .symmetric (horizontal: 12.0 , vertical: 8.0 ),
197
181
decoration: BoxDecoration (
@@ -256,18 +240,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
256
240
spacing: spacing,
257
241
children: [
258
242
Expanded (
259
- flex: 1 ,
260
- child: Align (
261
- alignment: Alignment .centerRight,
262
- child: animationWidget,
263
- ),
243
+ flex: 2 ,
244
+ child: animationWidget,
264
245
),
265
246
Flexible (
266
247
flex: 1 ,
267
- child: Align (
268
- alignment: Alignment .centerLeft,
269
- child: controlsWidget,
270
- ),
248
+ child: controlsWidget,
271
249
),
272
250
],
273
251
),
0 commit comments