@@ -5,6 +5,8 @@ import 'package:go_router/go_router.dart';
55import 'package:on_time_front/core/di/di_setup.dart' ;
66import 'package:on_time_front/presentation/calendar/bloc/monthly_schedules_bloc.dart' ;
77import 'package:on_time_front/presentation/calendar/component/schedule_detail.dart' ;
8+ import 'package:on_time_front/presentation/shared/components/calendar/centered_calendar_header.dart' ;
9+ import 'package:on_time_front/presentation/shared/theme/calendar_theme.dart' ;
810import 'package:table_calendar/table_calendar.dart' ;
911
1012class CalendarScreen extends ConsumerStatefulWidget {
@@ -18,13 +20,26 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
1820 DateTime _selectedDate =
1921 DateTime (DateTime .now ().year, DateTime .now ().month, DateTime .now ().day);
2022
23+ void _onLeftArrowTap () {
24+ setState (() {
25+ _selectedDate = DateTime (_selectedDate.year, _selectedDate.month - 1 , 1 );
26+ });
27+ }
28+
29+ void _onRightArrowTap () {
30+ setState (() {
31+ _selectedDate = DateTime (_selectedDate.year, _selectedDate.month + 1 , 1 );
32+ });
33+ }
34+
2135 @override
2236 Widget build (BuildContext context) {
2337 final theme = Theme .of (context);
2438 final textTheme = theme.textTheme;
2539 final colorScheme = theme.colorScheme;
2640 final todaysDate = DateTime (
2741 DateTime .now ().year, DateTime .now ().month, DateTime .now ().day, 0 , 0 , 0 );
42+ final calendarTheme = theme.extension < CalendarTheme > ()! ;
2843
2944 return BlocProvider (
3045 create: (context) => getIt.get <MonthlySchedulesBloc >()
@@ -47,78 +62,79 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
4762 children: [
4863 Container (
4964 decoration: BoxDecoration (
50- color: colorScheme.surface,
5165 borderRadius: BorderRadius .circular (11 ),
66+ color: colorScheme.surface,
5267 ),
53- child: BlocBuilder <MonthlySchedulesBloc , MonthlySchedulesState >(
54- builder: (context, state) {
55- if (state.status == MonthlySchedulesStatus .error) {
56- return Text ('Error' );
57- }
68+ child: Padding (
69+ padding: const EdgeInsets .symmetric (
70+ vertical: 16.0 , horizontal: 8.0 ),
71+ child:
72+ BlocBuilder <MonthlySchedulesBloc , MonthlySchedulesState >(
73+ builder: (context, state) {
74+ if (state.status == MonthlySchedulesStatus .error) {
75+ return Text ('Error' );
76+ }
5877
59- return TableCalendar (
60- eventLoader: (day) {
61- day = DateTime (day.year, day.month, day.day);
62- return state.schedules[day] ?? [];
63- },
64- focusedDay: _selectedDate,
65- firstDay: DateTime (2024 , 12 , 1 ),
66- lastDay: DateTime (2025 , 12 , 31 ),
67- calendarFormat: CalendarFormat .month,
68- headerStyle: HeaderStyle (
69- formatButtonVisible: false ,
70- titleCentered: true ,
71- ),
72- daysOfWeekStyle: DaysOfWeekStyle (
73- weekdayStyle: textTheme.bodySmall! ,
74- weekendStyle: textTheme.bodySmall! ,
75- ),
76- calendarStyle: CalendarStyle (
77- outsideDaysVisible: false ,
78- weekendTextStyle: textTheme.bodySmall! ,
79- defaultTextStyle: textTheme.bodySmall! ,
80- markerDecoration: BoxDecoration (
81- color: colorScheme.primary,
82- shape: BoxShape .circle,
83- ),
84- markerMargin: EdgeInsets .symmetric (horizontal: 1.0 ),
85- ),
86- onDaySelected: (selectedDay, focusedDay) {
87- setState (() {
88- _selectedDate = DateTime (selectedDay.year,
89- selectedDay.month, selectedDay.day);
90- });
91- debugPrint (selectedDay.toIso8601String ());
92- },
93- onPageChanged: (focusedDay) {
94- setState (() {
95- _selectedDate = DateTime (focusedDay.year,
96- focusedDay.month, focusedDay.day);
97- });
98- debugPrint (_selectedDate.toIso8601String ());
99- context.read <MonthlySchedulesBloc >().add (
100- MonthlySchedulesMonthAdded (
101- date: DateTime (focusedDay.year,
102- focusedDay.month, focusedDay.day)));
103- },
104- calendarBuilders: CalendarBuilders (
105- todayBuilder: (context, day, focusedDay) => Container (
106- margin: const EdgeInsets .all (4.0 ),
107- alignment: Alignment .center,
108- decoration: BoxDecoration (
109- color: theme.colorScheme.primary,
110- shape: BoxShape .circle,
111- ),
112- child: Text (
113- day.day.toString (),
114- style: textTheme.bodySmall? .copyWith (
115- color: theme.colorScheme.onPrimary,
78+ return TableCalendar (
79+ daysOfWeekHeight: 40 ,
80+ eventLoader: (day) {
81+ day = DateTime (day.year, day.month, day.day);
82+ return state.schedules[day] ?? [];
83+ },
84+ focusedDay: _selectedDate,
85+ firstDay: DateTime (2024 , 12 , 1 ),
86+ lastDay: DateTime (2025 , 12 , 31 ),
87+ calendarFormat: CalendarFormat .month,
88+ headerStyle: calendarTheme.headerStyle,
89+ daysOfWeekStyle: calendarTheme.daysOfWeekStyle,
90+ calendarStyle: calendarTheme.calendarStyle,
91+ onDaySelected: (selectedDay, focusedDay) {
92+ setState (() {
93+ _selectedDate = DateTime (selectedDay.year,
94+ selectedDay.month, selectedDay.day);
95+ });
96+ debugPrint (selectedDay.toIso8601String ());
97+ },
98+ onPageChanged: (focusedDay) {
99+ setState (() {
100+ _selectedDate = DateTime (focusedDay.year,
101+ focusedDay.month, focusedDay.day);
102+ });
103+ debugPrint (_selectedDate.toIso8601String ());
104+ context.read <MonthlySchedulesBloc >().add (
105+ MonthlySchedulesMonthAdded (
106+ date: DateTime (focusedDay.year,
107+ focusedDay.month, focusedDay.day)));
108+ },
109+ calendarBuilders: CalendarBuilders (
110+ headerTitleBuilder: (context, date) {
111+ return CenteredCalendarHeader (
112+ focusedMonth: date,
113+ onLeftArrowTap: _onLeftArrowTap,
114+ onRightArrowTap: _onRightArrowTap,
115+ titleTextStyle:
116+ calendarTheme.headerStyle.titleTextStyle,
117+ leftIcon:
118+ calendarTheme.headerStyle.leftChevronIcon,
119+ rightIcon:
120+ calendarTheme.headerStyle.rightChevronIcon,
121+ );
122+ },
123+ todayBuilder: (context, day, focusedDay) => Container (
124+ margin: const EdgeInsets .all (4.0 ),
125+ alignment: Alignment .center,
126+ decoration: calendarTheme.todayDecoration,
127+ child: Text (
128+ day.day.toString (),
129+ style: textTheme.bodySmall? .copyWith (
130+ color: theme.colorScheme.onPrimary,
131+ ),
116132 ),
117133 ),
118134 ),
119- ),
120- );
121- } ,
135+ );
136+ },
137+ ) ,
122138 ),
123139 ),
124140 SizedBox (height: 18.0 ),
0 commit comments