@@ -8,17 +8,19 @@ enum LevelStatus {
8
8
}
9
9
10
10
class LevelButton extends StatelessWidget {
11
+ final int levelNumber;
12
+ final LevelStatus status;
13
+ final int stars;
14
+ final bool isActive;
15
+ final Function ()? onTap;
11
16
12
- const LevelButton ({super .key,
17
+ LevelButton ({
13
18
required this .levelNumber,
14
19
required this .status,
15
20
this .stars = 0 ,
16
21
this .isActive = false ,
22
+ this .onTap,
17
23
});
18
- final int levelNumber;
19
- final LevelStatus status;
20
- final int stars;
21
- final bool isActive;
22
24
23
25
Color _getColor () {
24
26
switch (status) {
@@ -35,55 +37,62 @@ class LevelButton extends StatelessWidget {
35
37
36
38
@override
37
39
Widget build (BuildContext context) {
38
- return Container (
39
- width: 100 ,
40
- height: 100 ,
41
- margin: const EdgeInsets .all (10 ),
42
- decoration: BoxDecoration (
43
- shape: BoxShape .circle,
44
- color: _getColor (),
45
- ),
46
- child: Column (
47
- mainAxisAlignment: MainAxisAlignment .center,
48
- children: < Widget > [
49
- Text (
50
- levelNumber.toString (),
51
- style: const TextStyle (
52
- color: Colors .white,
53
- fontSize: 28 ,
54
- fontWeight: FontWeight .bold,
40
+ return GestureDetector (
41
+ onTap: () {
42
+ if (onTap != null ) {
43
+ onTap !();
44
+ }
45
+ },
46
+ child: Container (
47
+ width: 100 ,
48
+ height: 100 ,
49
+ margin: const EdgeInsets .all (10 ),
50
+ decoration: BoxDecoration (
51
+ shape: BoxShape .circle,
52
+ color: _getColor (),
53
+ ),
54
+ child: Column (
55
+ mainAxisAlignment: MainAxisAlignment .center,
56
+ children: < Widget > [
57
+ Text (
58
+ levelNumber.toString (),
59
+ style: const TextStyle (
60
+ color: Colors .white,
61
+ fontSize: 28 ,
62
+ fontWeight: FontWeight .bold,
63
+ ),
55
64
),
56
- ),
57
- if (stars > 0 )
58
- Row (
59
- mainAxisAlignment : MainAxisAlignment .center,
60
- children : List . generate (
61
- stars,
62
- ( int index) => const Icon (
63
- Icons .star ,
64
- color : Colors .white ,
65
- size : 20 ,
65
+ if (stars > 0 )
66
+ Row (
67
+ mainAxisAlignment : MainAxisAlignment .center,
68
+ children : List . generate (
69
+ stars,
70
+ (index) => const Icon (
71
+ Icons .star,
72
+ color : Colors .white ,
73
+ size : 20 ,
74
+ ) ,
66
75
),
67
76
),
68
- ) ,
69
- ] ,
77
+ ] ,
78
+ ) ,
70
79
),
71
80
);
72
81
}
73
82
}
74
83
75
84
class DashedLinePainter extends CustomPainter {
85
+ final Color color;
86
+ final double strokeWidth;
87
+ final double gap;
88
+ final double dashLength;
76
89
77
90
DashedLinePainter ({
78
91
required this .color,
79
92
this .strokeWidth = 2.0 ,
80
93
this .gap = 3.0 ,
81
94
this .dashLength = 5.0 ,
82
95
});
83
- final Color color;
84
- final double strokeWidth;
85
- final double gap;
86
- final double dashLength;
87
96
88
97
@override
89
98
void paint (Canvas canvas, Size size) {
@@ -93,8 +102,8 @@ class DashedLinePainter extends CustomPainter {
93
102
..style = PaintingStyle .stroke;
94
103
95
104
double startX = 0 ;
96
- final double startY = size.height / 2 ;
97
- final double endX = size.width;
105
+ double startY = size.height / 2 ;
106
+ double endX = size.width;
98
107
99
108
while (startX <= endX) {
100
109
canvas.drawLine (
@@ -114,12 +123,11 @@ class DashedLinePainter extends CustomPainter {
114
123
115
124
class Roadmap extends StatelessWidget {
116
125
const Roadmap ({super .key});
117
-
118
126
@override
119
127
Widget build (BuildContext context) {
120
128
return Scaffold (
121
129
appBar: AppBar (
122
- title: const Text ('Roadmap ' ),
130
+ title: const Text ('Candy Crush Levels ' ),
123
131
),
124
132
body: Stack (
125
133
children: < Widget > [
@@ -153,18 +161,18 @@ class Roadmap extends StatelessWidget {
153
161
}
154
162
155
163
Widget _buildLevelPath (int startLevel, int endLevel) {
156
- final Random random = Random ();
157
- final int numRows = (endLevel - startLevel + 1 ) ~ / 4 + 1 ; // Calculate number of rows
158
- final List <Widget > rows = < Widget > [];
164
+ final random = Random ();
165
+ int numRows = (endLevel - startLevel + 1 ) ~ / 4 + 1 ; // Calculate number of rows
166
+ List <Widget > rows = [];
159
167
160
168
for (int i = startLevel; i <= endLevel; i += 4 ) {
161
- final int levelsInRow = min (4 , endLevel - i + 1 ); // Calculate levels in this row
162
- final List <Widget > rowChildren = < Widget > [];
169
+ int levelsInRow = min (4 , endLevel - i + 1 ); // Calculate levels in this row
170
+ List <Widget > rowChildren = [];
163
171
164
172
for (int j = i; j < i + levelsInRow; j++ ) {
165
- final int currentLevel = j;
166
- final int nextLevel = currentLevel + 1 ;
167
- const bool isActive = true ; // Replace with your logic for active levels
173
+ int currentLevel = j;
174
+ int nextLevel = currentLevel + 1 ;
175
+ bool isActive = true ; // Replace with your logic for active levels
168
176
rowChildren.add (
169
177
Expanded (
170
178
child: Column (
@@ -174,14 +182,20 @@ class Roadmap extends StatelessWidget {
174
182
status: LevelStatus .completed, // Example status, modify as needed
175
183
stars: 3 , // Example stars, modify as needed
176
184
isActive: isActive,
185
+ onTap: () {
186
+ print ('Level $currentLevel clicked' );
187
+ // You can perform additional actions here based on the button click
188
+ },
177
189
),
178
- if (currentLevel < endLevel && j < i + levelsInRow - 1 ) // if (currentLevel < endLevel && j < i + levelsInRow - 1)
190
+ if (currentLevel < endLevel && j < i + levelsInRow - 1 )
179
191
SizedBox (
180
192
width: 60 ,
181
193
child: CustomPaint (
182
194
painter: DashedLinePainter (
183
195
color: Colors .white,
184
- dashLength: 10.0 ,
196
+ strokeWidth: 2.0 ,
197
+ gap: 3.0 ,
198
+ dashLength: 5.0 ,
185
199
),
186
200
),
187
201
),
0 commit comments