11import 'package:flutter/material.dart' ;
22import 'package:flutter_curve_visualizer/views/widgets/screen_mode.dart' ;
33import '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' ;
64import 'package:flutter_curve_visualizer/views/widgets/appbar.dart' ;
75import 'package:flutter_curve_visualizer/views/widgets/dropdown_menu.dart' ;
86import 'package:flutter_curve_visualizer/views/widgets/graph/graph_widget.dart' ;
7+ import 'widgets/animated_box/animated_boxes.dart' ;
98import 'widgets/code_block.dart' ;
109
1110class HomePage extends StatefulWidget {
@@ -70,6 +69,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
7069 }
7170
7271 void updateCurve (CurvesEnum curve) {
72+ if (curve == selectedCurve) return ;
73+
7374 setState (() {
7475 selectedCurve = curve;
7576 curveAnimation.curve = curve.curve;
@@ -115,11 +116,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
115116 Widget build (BuildContext context) {
116117 final screenMode = ScreenModeWidget .of (context);
117118
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;
123120
124121 final animationWidget = Column (
125122 children: [
@@ -130,34 +127,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
130127 ),
131128
132129 // 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),
161131 ],
162132 );
163133
@@ -167,31 +137,45 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
167137 ),
168138 child: Column (
169139 mainAxisSize: MainAxisSize .min,
140+ mainAxisAlignment: MainAxisAlignment .end,
170141 spacing: spacing,
171142 children: [
172143 // Code block
173144 CodeBlock (curve: selectedCurve),
174145
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+ ),
182161
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+ ],
192176 ),
193177
194- // Curve type
178+ // Animation time
195179 Container (
196180 padding: EdgeInsets .symmetric (horizontal: 12.0 , vertical: 8.0 ),
197181 decoration: BoxDecoration (
@@ -256,18 +240,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
256240 spacing: spacing,
257241 children: [
258242 Expanded (
259- flex: 1 ,
260- child: Align (
261- alignment: Alignment .centerRight,
262- child: animationWidget,
263- ),
243+ flex: 2 ,
244+ child: animationWidget,
264245 ),
265246 Flexible (
266247 flex: 1 ,
267- child: Align (
268- alignment: Alignment .centerLeft,
269- child: controlsWidget,
270- ),
248+ child: controlsWidget,
271249 ),
272250 ],
273251 ),
0 commit comments