Skip to content

Commit a8dc6e5

Browse files
committed
+ level onTap, + llm refactor
1 parent 7d19f84 commit a8dc6e5

File tree

4 files changed

+72
-59
lines changed

4 files changed

+72
-59
lines changed

lib/screens/dashboard/new_roadmap_screen.dart

+66-52
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ enum LevelStatus {
88
}
99

1010
class LevelButton extends StatelessWidget {
11+
final int levelNumber;
12+
final LevelStatus status;
13+
final int stars;
14+
final bool isActive;
15+
final Function()? onTap;
1116

12-
const LevelButton({super.key,
17+
LevelButton({
1318
required this.levelNumber,
1419
required this.status,
1520
this.stars = 0,
1621
this.isActive = false,
22+
this.onTap,
1723
});
18-
final int levelNumber;
19-
final LevelStatus status;
20-
final int stars;
21-
final bool isActive;
2224

2325
Color _getColor() {
2426
switch (status) {
@@ -35,55 +37,62 @@ class LevelButton extends StatelessWidget {
3537

3638
@override
3739
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+
),
5564
),
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+
),
6675
),
6776
),
68-
),
69-
],
77+
],
78+
),
7079
),
7180
);
7281
}
7382
}
7483

7584
class DashedLinePainter extends CustomPainter {
85+
final Color color;
86+
final double strokeWidth;
87+
final double gap;
88+
final double dashLength;
7689

7790
DashedLinePainter({
7891
required this.color,
7992
this.strokeWidth = 2.0,
8093
this.gap = 3.0,
8194
this.dashLength = 5.0,
8295
});
83-
final Color color;
84-
final double strokeWidth;
85-
final double gap;
86-
final double dashLength;
8796

8897
@override
8998
void paint(Canvas canvas, Size size) {
@@ -93,8 +102,8 @@ class DashedLinePainter extends CustomPainter {
93102
..style = PaintingStyle.stroke;
94103

95104
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;
98107

99108
while (startX <= endX) {
100109
canvas.drawLine(
@@ -114,12 +123,11 @@ class DashedLinePainter extends CustomPainter {
114123

115124
class Roadmap extends StatelessWidget {
116125
const Roadmap({super.key});
117-
118126
@override
119127
Widget build(BuildContext context) {
120128
return Scaffold(
121129
appBar: AppBar(
122-
title: const Text('Roadmap'),
130+
title: const Text('Candy Crush Levels'),
123131
),
124132
body: Stack(
125133
children: <Widget>[
@@ -153,18 +161,18 @@ class Roadmap extends StatelessWidget {
153161
}
154162

155163
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 = [];
159167

160168
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 = [];
163171

164172
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
168176
rowChildren.add(
169177
Expanded(
170178
child: Column(
@@ -174,14 +182,20 @@ class Roadmap extends StatelessWidget {
174182
status: LevelStatus.completed, // Example status, modify as needed
175183
stars: 3, // Example stars, modify as needed
176184
isActive: isActive,
185+
onTap: () {
186+
print('Level $currentLevel clicked');
187+
// You can perform additional actions here based on the button click
188+
},
177189
),
178-
if (currentLevel < endLevel && j < i + levelsInRow - 1) // if (currentLevel < endLevel && j < i + levelsInRow - 1)
190+
if (currentLevel < endLevel && j < i + levelsInRow - 1)
179191
SizedBox(
180192
width: 60,
181193
child: CustomPaint(
182194
painter: DashedLinePainter(
183195
color: Colors.white,
184-
dashLength: 10.0,
196+
strokeWidth: 2.0,
197+
gap: 3.0,
198+
dashLength: 5.0,
185199
),
186200
),
187201
),

lib/screens/main/components/others.dart lib/screens/main/components/llmchat.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class LLMChatApp extends StatelessWidget {
1414
primarySwatch: Colors.teal,
1515
visualDensity: VisualDensity.adaptivePlatformDensity,
1616
),
17-
home: const HomePage(),
17+
home: const LLMChat(),
1818
);
1919
}
2020
}
2121

22-
class HomePage extends StatelessWidget {
23-
const HomePage({super.key});
22+
class LLMChat extends StatelessWidget {
23+
const LLMChat({super.key});
2424

2525
@override
2626
Widget build(BuildContext context) {

lib/screens/main/main_screen.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '../games/select_the_area/select_the_area_screen.dart';
1212
import '../profile/profile_screen.dart';
1313
import '../settings/settings_screen.dart';
1414
import 'components/leaderboard.dart';
15-
import 'components/others.dart';
15+
import 'components/llmchat.dart';
1616
import 'components/side_menu.dart';
1717

1818
class MainScreen extends StatefulWidget {
@@ -43,7 +43,7 @@ class _MainScreenState extends State<MainScreen> {
4343
Widget page;
4444
switch (_selectedPage) {
4545
case 0:
46-
page = const Roadmap();
46+
page = Roadmap();
4747
// page = RoadmapScreen(onNavButtonPressed: upNavBarId);
4848
break;
4949
case 1:

lib/utils.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Future<User> checkIfUserOnDisk(String email, String country) async {
7373
level: level,
7474
country: country,
7575
);
76-
print(user);
7776
return user;
7877
}
7978
}
@@ -94,4 +93,4 @@ Future<Map<String, dynamic>> jwtDecode(String token) async {
9493
jsonDecode(response.body) as Map<String, dynamic>;
9594
return ret;
9695
}
97-
}
96+
}

0 commit comments

Comments
 (0)