Skip to content

Commit 695c2e0

Browse files
committed
Hide add button for past days
1 parent 23a1593 commit 695c2e0

4 files changed

Lines changed: 73 additions & 35 deletions

File tree

lib/presentation/calendar/screens/calendar_screen.dart

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class _CalendarScreenState extends State<CalendarScreen> {
117117
vertical: 16.0,
118118
horizontal: 8.0,
119119
),
120-
child: BlocBuilder<MonthlySchedulesBloc, MonthlySchedulesState>(
120+
child:
121+
BlocBuilder<MonthlySchedulesBloc, MonthlySchedulesState>(
121122
builder: (context, state) {
122123
if (state.status == MonthlySchedulesStatus.error) {
123124
return Text(AppLocalizations.of(context)!.error);
@@ -229,14 +230,26 @@ class _CalendarScreenState extends State<CalendarScreen> {
229230
BlocBuilder<MonthlySchedulesBloc, MonthlySchedulesState>(
230231
builder: (context, state) {
231232
if (state.schedules[_selectedDate]?.isEmpty ?? true) {
232-
if (state.status == MonthlySchedulesStatus.loading) {
233+
if (state.status ==
234+
MonthlySchedulesStatus.loading) {
233235
return const CircularProgressIndicator();
234236
}
235237

236-
if (state.status != MonthlySchedulesStatus.success) {
238+
if (state.status !=
239+
MonthlySchedulesStatus.success) {
237240
return const SizedBox();
238241
}
239242

243+
final now = DateTime.now();
244+
final today =
245+
DateTime(now.year, now.month, now.day);
246+
final selected = DateTime(
247+
_selectedDate.year,
248+
_selectedDate.month,
249+
_selectedDate.day,
250+
);
251+
final isPastSelectedDay = selected.isBefore(today);
252+
240253
return Padding(
241254
padding: const EdgeInsets.all(39.0),
242255
child: Column(
@@ -248,44 +261,50 @@ class _CalendarScreenState extends State<CalendarScreen> {
248261
color: theme.colorScheme.outlineVariant,
249262
),
250263
),
251-
ElevatedButton(
252-
onPressed: () {
253-
showModalBottomSheet(
254-
context: context,
255-
isScrollControlled: true,
256-
backgroundColor: Colors.transparent,
257-
builder: (context) =>
258-
const ScheduleCreateScreen(),
259-
);
260-
},
261-
style: ElevatedButton.styleFrom(
262-
backgroundColor: theme.colorScheme.surface,
263-
side: BorderSide(
264-
width: 0.5,
265-
color: theme.colorScheme.outlineVariant,
266-
),
267-
padding: const EdgeInsets.symmetric(
268-
vertical: 4.0,
269-
horizontal: 12.0,
264+
if (!isPastSelectedDay)
265+
ElevatedButton(
266+
onPressed: () {
267+
showModalBottomSheet(
268+
context: context,
269+
isScrollControlled: true,
270+
backgroundColor: Colors.transparent,
271+
builder: (context) =>
272+
ScheduleCreateScreen(
273+
initialDate: _selectedDate,
274+
),
275+
);
276+
},
277+
style: ElevatedButton.styleFrom(
278+
backgroundColor:
279+
theme.colorScheme.surface,
280+
side: BorderSide(
281+
width: 0.5,
282+
color:
283+
theme.colorScheme.outlineVariant,
284+
),
285+
padding: const EdgeInsets.symmetric(
286+
vertical: 4.0,
287+
horizontal: 12.0,
288+
),
270289
),
271-
),
272-
child: Text(
273-
AppLocalizations.of(context)!
274-
.addAppointment,
275-
style: textTheme.bodyMedium?.copyWith(
276-
color:
277-
theme.colorScheme.onSurfaceVariant,
290+
child: Text(
291+
AppLocalizations.of(context)!
292+
.addAppointment,
293+
style: textTheme.bodyMedium?.copyWith(
294+
color: theme
295+
.colorScheme.onSurfaceVariant,
296+
),
278297
),
279298
),
280-
),
281299
],
282300
),
283301
);
284302
}
285303

286304
return Expanded(
287305
child: ListView.builder(
288-
itemCount: state.schedules[_selectedDate]?.length ?? 0,
306+
itemCount:
307+
state.schedules[_selectedDate]?.length ?? 0,
289308
itemBuilder: (context, index) {
290309
final schedule =
291310
state.schedules[_selectedDate]![index];

lib/presentation/schedule_create/bloc/schedule_form_bloc.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,23 @@ class ScheduleFormBloc extends Bloc<ScheduleFormEvent, ScheduleFormState> {
101101
final userSpareTime = _authBloc.state.user.mapOrNull(
102102
(user) => user.spareTime,
103103
);
104+
final now = DateTime.now();
105+
final initialScheduleTime = event.initialDate == null
106+
? null
107+
: DateTime(
108+
event.initialDate!.year,
109+
event.initialDate!.month,
110+
event.initialDate!.day,
111+
now.hour,
112+
now.minute,
113+
);
104114

105115
emit(state.copyWith(
106116
status: ScheduleFormStatus.success,
107117
id: Uuid().v7(),
108118
placeName: null,
109119
scheduleName: null,
110-
scheduleTime: null,
120+
scheduleTime: initialScheduleTime,
111121
moveTime: null,
112122
isChanged: null,
113123
scheduleSpareTime: userSpareTime,

lib/presentation/schedule_create/bloc/schedule_form_event.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ final class ScheduleFormEditRequested extends ScheduleFormEvent {
1717
}
1818

1919
final class ScheduleFormCreateRequested extends ScheduleFormEvent {
20-
const ScheduleFormCreateRequested();
20+
final DateTime? initialDate;
21+
22+
const ScheduleFormCreateRequested({this.initialDate});
23+
24+
@override
25+
List<Object> get props => [
26+
initialDate ?? DateTime.fromMillisecondsSinceEpoch(0),
27+
];
2128
}
2229

2330
final class ScheduleFormScheduleNameChanged extends ScheduleFormEvent {

lib/presentation/schedule_create/screens/schedule_create_screen.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'package:on_time_front/presentation/schedule_create/bloc/schedule_form_bl
66
import 'package:on_time_front/presentation/schedule_create/components/schedule_multi_page_form.dart';
77

88
class ScheduleCreateScreen extends StatelessWidget {
9-
const ScheduleCreateScreen({super.key});
9+
const ScheduleCreateScreen({super.key, this.initialDate});
10+
11+
final DateTime? initialDate;
1012

1113
@override
1214
Widget build(BuildContext context) {
@@ -29,7 +31,7 @@ class ScheduleCreateScreen extends StatelessWidget {
2931
child: BlocProvider<ScheduleFormBloc>(
3032
create: (context) => getIt.get<ScheduleFormBloc>(
3133
param1: context.read<AuthBloc>(),
32-
)..add(ScheduleFormCreateRequested()),
34+
)..add(ScheduleFormCreateRequested(initialDate: initialDate)),
3335
child: BlocBuilder<ScheduleFormBloc, ScheduleFormState>(
3436
builder: (context, state) {
3537
return ScheduleMultiPageForm(

0 commit comments

Comments
 (0)