1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_svg/flutter_svg.dart' ;
2
3
import 'package:on_time_front/domain/entities/schedule_entity.dart' ;
3
4
import 'package:on_time_front/presentation/shared/constants/app_colors.dart' ;
4
5
5
6
class TodaysScheduleTile extends StatelessWidget {
6
7
const TodaysScheduleTile ({super .key, this .schedule});
7
8
8
9
final ScheduleEntity ? schedule;
9
- Widget noSchedule (BuildContext context) {
10
+
11
+ Widget _noSchedule (BuildContext context) {
10
12
final theme = Theme .of (context);
11
- return Text (
12
- '약속이 없는 날이에요' ,
13
- style: theme.textTheme.bodyLarge? .copyWith (
14
- color: theme.colorScheme.outlineVariant,
13
+ return Center (
14
+ child: Text (
15
+ '약속이 없는 날이에요' ,
16
+ style: theme.textTheme.bodyLarge? .copyWith (
17
+ color: theme.colorScheme.outlineVariant,
18
+ ),
15
19
),
16
20
);
17
21
}
18
22
19
- Widget scheduleExists (BuildContext context) {
20
- return Row (
21
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
22
- children: [
23
- Text (
24
- '${schedule !.scheduleTime .hour > 12 ? '오후' : '오전' } ${schedule !.scheduleTime .hour % 12 }시 ${schedule !.scheduleTime .minute }분' ,
25
- style: TextStyle (color: AppColors .white),
26
- ),
27
- Text (
28
- schedule! .scheduleName,
29
- style: TextStyle (color: AppColors .white),
30
- ),
31
- SizedBox (height: 8.0 ),
32
- // - 시간 - 분 전
33
- Text (
34
- '${schedule !.scheduleTime .difference (DateTime .now ()).inHours }시간 ${schedule !.scheduleTime .difference (DateTime .now ()).inMinutes % 60 }분 전' ,
35
- style: TextStyle (color: AppColors .white),
36
- ),
37
- ],
23
+ Widget _scheduleExists (BuildContext context) {
24
+ final theme = Theme .of (context);
25
+ final colorScheme = theme.colorScheme;
26
+ final scheduleTime = schedule! .scheduleTime;
27
+ final now = DateTime .now ();
28
+ final difference = scheduleTime.difference (now);
29
+
30
+ // Calculate hours and minutes until schedule
31
+ final hoursUntil = difference.inHours;
32
+ final minutesUntil = difference.inMinutes % 60 ;
33
+
34
+ // Determine AM/PM and format hour
35
+ final hour = scheduleTime.hour;
36
+ final period = hour >= 12 ? 'PM' : 'AM' ;
37
+ final displayHour = hour == 0 ? 12 : (hour > 12 ? hour - 12 : hour);
38
+
39
+ return IntrinsicHeight (
40
+ child: Row (
41
+ crossAxisAlignment: CrossAxisAlignment .start,
42
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
43
+ children: [
44
+ Padding (
45
+ padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
46
+ child: _ScheduleLeftTimeColumn (
47
+ scheduleTime: schedule! .scheduleTime,
48
+ ),
49
+ ),
50
+ VerticalDivider (
51
+ width: 1 ,
52
+ color: colorScheme.primary,
53
+ ),
54
+ Expanded (
55
+ child: Padding (
56
+ padding:
57
+ const EdgeInsets .symmetric (horizontal: 21.0 , vertical: 11.0 ),
58
+ child: _ScheduleDetailsColumn (
59
+ schedule: schedule! ,
60
+ ),
61
+ ),
62
+ ),
63
+ ],
64
+ ),
38
65
);
39
66
}
40
67
@@ -45,14 +72,102 @@ class TodaysScheduleTile extends StatelessWidget {
45
72
decoration: BoxDecoration (
46
73
color: schedule == null
47
74
? theme.colorScheme.surfaceContainerLow
48
- : theme.colorScheme.primary ,
49
- borderRadius: BorderRadius .circular (11 ),
75
+ : theme.colorScheme.primaryContainer ,
76
+ borderRadius: BorderRadius .circular (16 ),
50
77
),
51
78
width: double .infinity,
52
79
child: Padding (
53
- padding: const EdgeInsets .symmetric (horizontal: 11.0 , vertical: 16.0 ),
54
- child: schedule == null ? noSchedule (context) : scheduleExists (context),
80
+ padding: const EdgeInsets .symmetric (vertical: 6.5 ),
81
+ child:
82
+ schedule == null ? _noSchedule (context) : _scheduleExists (context),
55
83
),
56
84
);
57
85
}
58
86
}
87
+
88
+ class _ScheduleDetailsColumn extends StatelessWidget {
89
+ const _ScheduleDetailsColumn ({required this .schedule});
90
+
91
+ final ScheduleEntity schedule;
92
+
93
+ @override
94
+ Widget build (BuildContext context) {
95
+ final theme = Theme .of (context);
96
+ final colorScheme = theme.colorScheme;
97
+ final textTheme = theme.textTheme;
98
+ final hour = schedule.scheduleTime.hour;
99
+ final period = hour >= 12 ? 'PM' : 'AM' ;
100
+ final displayHour = hour == 0 ? 12 : (hour > 12 ? hour - 12 : hour);
101
+
102
+ return Column (
103
+ crossAxisAlignment: CrossAxisAlignment .start,
104
+ children: [
105
+ Text (
106
+ schedule.scheduleName,
107
+ style: textTheme.titleLarge? .copyWith (color: colorScheme.primary),
108
+ ),
109
+ //time PM H:MM
110
+ Text (
111
+ '$period ${displayHour .toString ().padLeft (2 , '0' )}:${schedule .scheduleTime .minute .toString ().padLeft (2 , '0' )}' ,
112
+ style: textTheme.bodySmall? .copyWith (color: colorScheme.primary),
113
+ ),
114
+ ],
115
+ );
116
+ }
117
+ }
118
+
119
+ class _ScheduleLeftTimeColumn extends StatelessWidget {
120
+ const _ScheduleLeftTimeColumn ({required this .scheduleTime});
121
+
122
+ final DateTime scheduleTime;
123
+
124
+ @override
125
+ Widget build (BuildContext context) {
126
+ final leftTime = scheduleTime.difference (DateTime .now ());
127
+ //약속까지 hh:mm
128
+ final hours = leftTime.inHours;
129
+ final minutes = leftTime.inMinutes % 60 ;
130
+
131
+ return _TimeColumn (
132
+ hour: hours,
133
+ minute: minutes,
134
+ );
135
+ }
136
+ }
137
+
138
+ class _TimeColumn extends StatelessWidget {
139
+ const _TimeColumn ({
140
+ required this .hour,
141
+ required this .minute,
142
+ });
143
+
144
+ final int hour;
145
+ final int minute;
146
+
147
+ @override
148
+ Widget build (BuildContext context) {
149
+ final theme = Theme .of (context);
150
+ final colorScheme = theme.colorScheme;
151
+ return Column (
152
+ crossAxisAlignment: CrossAxisAlignment .center,
153
+ mainAxisAlignment: MainAxisAlignment .center,
154
+ children: [
155
+ Text (
156
+ "약속까지" ,
157
+ style: theme.textTheme.bodySmall? .copyWith (
158
+ color: colorScheme.primary,
159
+ ),
160
+ textAlign: TextAlign .center,
161
+ ),
162
+ const SizedBox (height: 4 ),
163
+ Text (
164
+ '${hour .toString ().padLeft (2 , '0' )}:${minute .toString ().padLeft (2 , '0' )}' ,
165
+ style: theme.textTheme.titleSmall? .copyWith (
166
+ color: colorScheme.primary,
167
+ ),
168
+ textAlign: TextAlign .center,
169
+ ),
170
+ ],
171
+ );
172
+ }
173
+ }
0 commit comments