Skip to content

Commit bc0eebe

Browse files
committed
refactor, level button manager added
1 parent e211a26 commit bc0eebe

10 files changed

+211
-380
lines changed

lib/main.dart

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:web/web.dart';
1111
import 'constants.dart';
1212
import 'controllers/menu_app_controller.dart';
1313
import 'models/user_data.dart';
14+
import 'screens/dashboard/components/level_button.dart';
1415
import 'screens/main/main_screen.dart';
1516
import 'utils.dart';
1617

@@ -59,7 +60,12 @@ void main() async {
5960
UserManager.instance.user = user;
6061

6162
final User myuser = UserManager.instance.user;
63+
6264
user.addScore(50);
65+
66+
final List<LevelButton> levels = initializeLevelButtons();
67+
LevelButtonManager.instance.levelButtons = levels;
68+
6369
debugPaintSizeEnabled = false;
6470
runApp(const MyApp());
6571
}

lib/screens/dashboard/components/chart.dart

-79
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:flutter/material.dart';
2+
3+
class DashedLinePainter extends CustomPainter {
4+
DashedLinePainter({
5+
required this.color,
6+
this.strokeWidth = 2.0,
7+
this.gap = 3.0,
8+
this.dashLength = 5.0,
9+
});
10+
final Color color;
11+
final double strokeWidth;
12+
final double gap;
13+
final double dashLength;
14+
15+
@override
16+
void paint(Canvas canvas, Size size) {
17+
final Paint paint = Paint()
18+
..color = color
19+
..strokeWidth = strokeWidth
20+
..style = PaintingStyle.stroke;
21+
22+
double startX = 0;
23+
final double startY = size.height / 2;
24+
final double endX = size.width;
25+
26+
while (startX <= endX) {
27+
canvas.drawLine(
28+
Offset(startX, startY),
29+
Offset(startX + dashLength, startY),
30+
paint,
31+
);
32+
startX += dashLength + gap;
33+
}
34+
}
35+
36+
@override
37+
bool shouldRepaint(covariant CustomPainter oldDelegate) {
38+
return false;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import 'package:flutter/material.dart';
2+
3+
enum LevelStatus {
4+
locked,
5+
inProgress,
6+
completed,
7+
}
8+
9+
class LevelButton extends StatelessWidget {
10+
LevelButton(
11+
{super.key,
12+
required this.levelNumber,
13+
required this.status,
14+
this.levelScore = 0,
15+
this.stars = 0,
16+
this.isActive = false,
17+
this.onTapLevelButton});
18+
19+
final int levelNumber;
20+
LevelStatus status;
21+
int levelScore;
22+
int stars;
23+
bool isActive;
24+
void Function(int, int)? onTapLevelButton;
25+
26+
Color _getColor() {
27+
switch (status) {
28+
case LevelStatus.locked:
29+
return Colors.red;
30+
case LevelStatus.inProgress:
31+
return isActive ? Colors.yellow : Colors.grey;
32+
case LevelStatus.completed:
33+
return Colors.green;
34+
default:
35+
return Colors.grey;
36+
}
37+
}
38+
39+
void addLevelScore(int score) {
40+
levelScore += score;
41+
}
42+
43+
@override
44+
Widget build(BuildContext context) {
45+
return GestureDetector(
46+
onTap: () {
47+
if ((onTapLevelButton != null) && isActive) {
48+
onTapLevelButton!(levelNumber, stars);
49+
}
50+
},
51+
child: Container(
52+
width: 100,
53+
height: 100,
54+
margin: const EdgeInsets.all(10),
55+
decoration: BoxDecoration(
56+
shape: BoxShape.circle,
57+
color: _getColor(),
58+
),
59+
child: Column(
60+
mainAxisAlignment: MainAxisAlignment.center,
61+
children: <Widget>[
62+
Text(
63+
levelNumber.toString(),
64+
style: const TextStyle(
65+
color: Colors.white,
66+
fontSize: 28,
67+
fontWeight: FontWeight.bold,
68+
),
69+
),
70+
if (stars > 0)
71+
Row(
72+
mainAxisAlignment: MainAxisAlignment.center,
73+
children: List.generate(
74+
stars,
75+
(int index) => const Icon(
76+
Icons.star,
77+
color: Colors.white,
78+
size: 20,
79+
),
80+
),
81+
),
82+
],
83+
),
84+
),
85+
);
86+
}
87+
}

lib/screens/dashboard/components/storage_details.dart

-60
This file was deleted.

lib/screens/dashboard/components/storage_info_card.dart

-63
This file was deleted.

0 commit comments

Comments
 (0)