-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcourse_table_block.dart
More file actions
175 lines (165 loc) · 4.81 KB
/
course_table_block.dart
File metadata and controls
175 lines (165 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';
import 'package:tattoo/components/app_skeleton.dart';
import 'package:tattoo/components/widget_preview_frame.dart';
import 'package:tattoo/models/course.dart';
import 'package:tattoo/repositories/course_repository.dart';
import 'package:auto_size_text/auto_size_text.dart';
class CourseTableBlock extends StatelessWidget {
final CourseTableBlockObject courseBlock;
final Color blockColor;
const CourseTableBlock({
required this.courseBlock,
required this.blockColor,
super.key,
});
@override
Widget build(BuildContext context) {
final containerColor = HSLColor.fromColor(
blockColor,
).withLightness(0.95).withSaturation(0.3).toColor();
final borderColor = HSLColor.fromColor(
blockColor,
).withLightness(0.3).withSaturation(0.8).toColor();
final borderStyle = Border.all(
color: borderColor,
width: 1,
);
final theme = Theme.of(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
child: Container(
decoration: BoxDecoration(
color: containerColor,
borderRadius: BorderRadius.circular(8),
border: borderStyle,
),
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 2),
child: SizedBox(
height: 64,
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AutoSizeText(
courseBlock.courseNameZh ?? courseBlock.courseNumber,
style: theme.textTheme.bodyMedium?.copyWith(
fontSize: 12,
fontWeight: FontWeight.w700,
),
maxLines: 2,
minFontSize: 10,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
AutoSizeText(
courseBlock.classroomNameZh,
style: theme.textTheme.bodySmall?.copyWith(
fontSize: 8,
fontWeight: FontWeight.w400,
),
maxLines: 1,
minFontSize: 6,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
),
),
);
}
}
class CourseTableBlockSkeleton extends StatelessWidget {
const CourseTableBlockSkeleton({super.key});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final baseColor = colorScheme.surfaceContainerHighest;
final borderColor = colorScheme.outlineVariant;
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(color: borderColor, width: 1),
),
clipBehavior: Clip.antiAlias,
child: Skeletonizer(
effect: PulseEffect(
from: baseColor,
to: borderColor,
duration: const Duration(milliseconds: 800),
),
child: Skeleton.leaf(
child: Container(color: baseColor),
),
),
);
}
}
@Preview(
name: 'Named Course',
group: 'Course Table',
size: Size(220, 150),
)
Widget courseTableBlockNamedPreview() {
return WidgetPreviewFrame(
child: Row(
spacing: 4,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 50,
height: 68,
child: CourseTableBlock(
courseBlock: _previewNamedCourseTableBlock,
blockColor: Colors.blue,
),
),
SizedBox(
width: 50,
height: 136,
child: CourseTableBlock(
courseBlock: _previewNamedCourseTableBlock,
blockColor: Colors.red,
),
),
],
),
);
}
@Preview(
name: 'CourseTableBlockSkeleton',
group: 'Course Table',
size: Size(220, 150),
)
Widget courseTableBlockSkeletonPreview() {
return WidgetPreviewFrame(
child: Row(
spacing: 4,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
width: 50,
height: 68,
child: CourseTableBlockSkeleton(),
),
const SizedBox(
width: 50,
height: 136,
child: CourseTableBlockSkeleton(),
),
],
),
);
}
final CourseTableBlockObject _previewNamedCourseTableBlock = (
courseNumber: 'CSIE3001',
courseNameZh: '微處理機及自動控制應用實務',
classroomNameZh: '六教305',
dayOfWeek: DayOfWeek.monday,
startSection: Period.third,
endSection: Period.fourth,
);