Skip to content

Commit 807c324

Browse files
author
Vivek Chib
committed
1. added curve category and type in a row
2. refactored and extracted animated boxes widget 3. added spacing getter to ScreenMode widget
1 parent a26bb4d commit 807c324

File tree

5 files changed

+104
-71
lines changed

5 files changed

+104
-71
lines changed

lib/views/home_page.dart

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_curve_visualizer/views/widgets/screen_mode.dart';
33
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';
64
import 'package:flutter_curve_visualizer/views/widgets/appbar.dart';
75
import 'package:flutter_curve_visualizer/views/widgets/dropdown_menu.dart';
86
import 'package:flutter_curve_visualizer/views/widgets/graph/graph_widget.dart';
7+
import 'widgets/animated_box/animated_boxes.dart';
98
import 'widgets/code_block.dart';
109

1110
class 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
),
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_curve_visualizer/utils/extension/string.dart';
3+
import 'package:flutter_curve_visualizer/views/widgets/screen_mode.dart';
4+
5+
import 'animated_box_widget.dart';
6+
7+
class AnimationBoxes extends StatelessWidget {
8+
const AnimationBoxes({super.key, required this.curveAnimation});
9+
10+
final CurvedAnimation curveAnimation;
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
final screenMode = ScreenModeWidget.of(context);
15+
16+
final spacing = screenMode.spacing;
17+
18+
return SizedBox(
19+
width: MediaQuery.of(context).size.width /
20+
(screenMode.isMobileOrTablet ? 1 : 2),
21+
child: Wrap(
22+
spacing: spacing / 2,
23+
runSpacing: spacing / 2,
24+
runAlignment: WrapAlignment.center,
25+
alignment: WrapAlignment.center,
26+
children: AnimationType.values.map(
27+
(animationType) {
28+
return Column(
29+
mainAxisAlignment: MainAxisAlignment.start,
30+
spacing: 8.0,
31+
children: [
32+
Text(animationType.name.capitalizeFirst()),
33+
SizedBox.square(
34+
dimension: 100,
35+
child: AnimatedBoxWidget(
36+
animationType: animationType,
37+
animation: curveAnimation,
38+
),
39+
),
40+
],
41+
);
42+
},
43+
).toList(),
44+
),
45+
);
46+
}
47+
}

lib/views/widgets/dropdown_menu.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
class DropdownMenuWidget<T> extends StatelessWidget {
4+
final double? width;
45
final String title;
56
final T? value;
67
final List<T> items;
@@ -12,6 +13,7 @@ class DropdownMenuWidget<T> extends StatelessWidget {
1213
super.key,
1314
required this.title,
1415
required this.items,
16+
this.width,
1517
this.childBuilder,
1618
this.onChanged,
1719
this.value,
@@ -24,6 +26,7 @@ class DropdownMenuWidget<T> extends StatelessWidget {
2426
final childTextStyle = Theme.of(context).textTheme.titleMedium;
2527

2628
return Container(
29+
width: width,
2730
padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
2831
decoration: BoxDecoration(
2932
color: Theme.of(context).colorScheme.onPrimaryFixed,

lib/views/widgets/screen_mode.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ enum ScreenMode {
1313

1414
bool get isMobileOrTablet =>
1515
this == ScreenMode.mobile || this == ScreenMode.tablet;
16+
17+
double get spacing => switch (this) {
18+
ScreenMode.mobile => 10,
19+
ScreenMode.tablet => 20,
20+
ScreenMode.web => 20,
21+
};
1622
}
1723

1824
class ScreenModeWidget extends InheritedWidget {

makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
BASE_HREF = '/'
22
GITHUB_REPO := https://github.com/vchib1/vchib1.github.io.git
33

4-
build:
4+
clean:
55
@echo "Cleaning up..."
66
flutter clean
77
@echo "Getting Packages..."
88
flutter pub get
9-
@echo "Building Web..."
10-
flutter build web --wasm
9+
@echo "Success..."
1110

12-
deploy:
11+
build:
1312
@echo "Cleaning up..."
1413
flutter clean
1514
@echo "Getting Packages..."
1615
flutter pub get
1716
@echo "Building Web..."
17+
flutter build web --wasm
18+
19+
deploy:
20+
make clean
21+
@echo "Building Web..."
1822
flutter build web --base-href $(BASE_HREF) --release
1923
@echo "Deploying Web to Repository..."
2024
cd build/web && \
@@ -29,14 +33,9 @@ deploy:
2933
@echo "Deployment Success :)"
3034

3135
host:
36+
make clean
3237
flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0 --profile
3338
@echo "Web server running on http://localhost:8080"
3439

35-
clean:
36-
@echo "Cleaning up..."
37-
flutter clean
38-
@echo "Getting Packages..."
39-
flutter pub get
40-
@echo "Success..."
4140

4241
.phony: host clean deploy

0 commit comments

Comments
 (0)