Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/enumerations.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
enum CalendarView { month, day, week }
enum CalendarView { month, day, week, multiDay }
16 changes: 16 additions & 0 deletions example/lib/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ extension StringExt on String {
String get capitalized => toBeginningOfSentenceCase(this) ?? "";
}

extension TimeOfDayExtension on TimeOfDay {
/// Formats the time as a string (e.g., "2:30 PM" or "14:30")
String getTimeInFormat(TimeStampFormat format) {
if (format == TimeStampFormat.parse_12) {
final period = hour >= 12 ? 'PM' : 'AM';
final displayHour = hour == 0 ? 12 : (hour > 12 ? hour - 12 : hour);
final minuteStr = minute.toString().padLeft(2, '0');
return '$displayHour:$minuteStr $period';
} else {
final hourStr = hour.toString().padLeft(2, '0');
final minuteStr = minute.toString().padLeft(2, '0');
return '$hourStr:$minuteStr';
}
}
}

extension ViewNameExt on CalendarView {
String get name => toString().split(".").last;
}
Expand Down
6 changes: 5 additions & 1 deletion example/lib/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@
"done": "تم",
"selectLanguage": "اختر اللغة",
"reachedTheEndPage": "لقد وصلت إلى نهاية الصفحة",
"reachedTheStartPage": "لقد وصلت إلى بداية الصفحة"
"reachedTheStartPage": "لقد وصلت إلى بداية الصفحة",
"annualTechConferenceTitle": "المؤتمر التقني السنوي",
"annualTechConferenceDesc": "حضور المؤتمر التقني السنوي.",
"extendedWorkshopTitle": "ورشة عمل موسعة",
"extendedWorkshopDesc": "المشاركة في ورشة العمل الموسعة لتطوير البرمجيات."
}
6 changes: 5 additions & 1 deletion example/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@
"done": "Done",
"selectLanguage": "Select Language",
"reachedTheEndPage": "You have reached the end of the page",
"reachedTheStartPage": "You have reached the start of the page"
"reachedTheStartPage": "You have reached the start of the page",
"annualTechConferenceTitle": "Annual Tech Conference",
"annualTechConferenceDesc": "Attend the annual tech conference.",
"extendedWorkshopTitle": "Extended Workshop",
"extendedWorkshopDesc": "Participate in the extended software development workshop."
}
6 changes: 5 additions & 1 deletion example/lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@
"done": "Hecho",
"selectLanguage": "Seleccionar idioma",
"reachedTheEndPage": "Has llegado al final de la página.",
"reachedTheStartPage": "Has llegado al inicio de la página."
"reachedTheStartPage": "Has llegado al inicio de la página.",
"annualTechConferenceTitle": "Conferencia Anual de Tecnología",
"annualTechConferenceDesc": "Asistir a la conferencia anual de tecnología.",
"extendedWorkshopTitle": "Taller Extendido",
"extendedWorkshopDesc": "Participa en el taller extendido de desarrollo de software."
}
128 changes: 61 additions & 67 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,103 +34,97 @@ class _HomePageState extends State<HomePage> {

final translate = context.translate;
final events = [
CalendarEventData(
date: _now,
// Example of timeRanged event - for events with specific start/end times on a single day
CalendarEventData.timeRanged(
title: translate.projectMeetingTitle,
description: translate.projectMeetingDesc,
startTime: DateTime(_now.year, _now.month, _now.day, 18, 30),
endTime: DateTime(_now.year, _now.month, _now.day, 22),
date: _now,
startTime: const TimeOfDay(hour: 18, minute: 30),
endTime: const TimeOfDay(hour: 22, minute: 0),
),
CalendarEventData(
date: _now.subtract(Duration(days: 3)),
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
startDate: _now.subtract(Duration(days: 3)),
),
// Example of wholeDay event with recurrence - for all-day events
CalendarEventData.wholeDay(
title: translate.leetcodeContestTitle,
description: translate.leetcodeContestDesc,
date: _now.subtract(const Duration(days: 3)),
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
startDate: _now.subtract(const Duration(days: 3)),
),
),
CalendarEventData(
date: _now.subtract(Duration(days: 3)),
// Example of wholeDay event with daily recurrence
CalendarEventData.wholeDay(
title: translate.physicsTestTitle,
description: translate.physicsTestDesc,
date: _now.subtract(const Duration(days: 3)),
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
startDate: _now.subtract(Duration(days: 3)),
startDate: _now.subtract(const Duration(days: 3)),
frequency: RepeatFrequency.daily,
recurrenceEndOn: RecurrenceEnd.after,
occurrences: 5,
),
title: translate.physicsTestTitle,
description: translate.physicsTestDesc,
),
CalendarEventData(
date: _now.add(Duration(days: 1)),
startTime: DateTime(_now.year, _now.month, _now.day, 18),
endTime: DateTime(_now.year, _now.month, _now.day, 19),
// Example of timeRanged event with recurrence
CalendarEventData.timeRanged(
title: translate.weddingAnniversaryTitle,
description: translate.weddingAnniversaryDesc,
date: _now.add(const Duration(days: 1)),
startTime: const TimeOfDay(hour: 18, minute: 0),
endTime: const TimeOfDay(hour: 19, minute: 0),
recurrenceSettings: RecurrenceSettings(
startDate: _now,
endDate: _now.add(Duration(days: 5)),
endDate: _now.add(const Duration(days: 5)),
frequency: RepeatFrequency.daily,
recurrenceEndOn: RecurrenceEnd.after,
occurrences: 5,
),
title: translate.weddingAnniversaryTitle,
description: translate.weddingAnniversaryDesc,
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 14),
endTime: DateTime(_now.year, _now.month, _now.day, 17),
// Example of timeRanged event - afternoon tournament
CalendarEventData.timeRanged(
title: translate.footballTournamentTitle,
description: translate.footballTournamentDesc,
date: _now,
startTime: const TimeOfDay(hour: 14, minute: 0),
endTime: const TimeOfDay(hour: 17, minute: 0),
),
CalendarEventData(
date: _now.add(Duration(days: 3)),
startTime: DateTime(
_now.add(Duration(days: 3)).year,
_now.add(Duration(days: 3)).month,
_now.add(Duration(days: 3)).day,
10,
),
endTime: DateTime(
_now.add(Duration(days: 3)).year,
_now.add(Duration(days: 3)).month,
_now.add(Duration(days: 3)).day,
14,
),
// Example of timeRanged event - morning meeting
CalendarEventData.timeRanged(
title: translate.sprintMeetingTitle,
description: translate.sprintMeetingDesc,
date: _now.add(const Duration(days: 3)),
startTime: const TimeOfDay(hour: 10, minute: 0),
endTime: const TimeOfDay(hour: 14, minute: 0),
),
CalendarEventData(
date: _now.subtract(Duration(days: 2)),
startTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
14,
),
endTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
16,
),
// Example of timeRanged event - 2 hour meeting
CalendarEventData.timeRanged(
title: translate.teamMeetingTitle,
description: translate.teamMeetingDesc,
date: _now.subtract(const Duration(days: 2)),
startTime: const TimeOfDay(hour: 14, minute: 0),
endTime: const TimeOfDay(hour: 16, minute: 0),
),
CalendarEventData(
date: _now.subtract(Duration(days: 2)),
startTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
10,
),
endTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
12,
),
// Example of timeRanged event - chemistry viva
CalendarEventData.timeRanged(
title: translate.chemistryVivaTitle,
description: translate.chemistryVivaDesc,
date: _now.subtract(const Duration(days: 2)),
startTime: const TimeOfDay(hour: 10, minute: 0),
endTime: const TimeOfDay(hour: 12, minute: 0),
),
// Example of multiDay event - spanning multiple days without specific times
CalendarEventData.multiDay(
title: translate.annualTechConferenceTitle,
description: translate.annualTechConferenceDesc,
startDate: _now.add(const Duration(days: 5)),
endDate: _now.add(const Duration(days: 7)),
),
// Example of multiDay event with specific times - workshop spanning multiple days
CalendarEventData.multiDay(
title: translate.extendedWorkshopTitle,
description: translate.extendedWorkshopDesc,
startDate: _now.add(const Duration(days: 10)),
endDate: _now.add(const Duration(days: 12)),
startTime: const TimeOfDay(hour: 9, minute: 0),
endTime: const TimeOfDay(hour: 17, minute: 0),
),
];
_controller!.addAll(events);
Expand Down
55 changes: 40 additions & 15 deletions example/lib/widgets/add_event_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
}
});
},
activeThumbColor: color.surface,
activeTrackColor: color.onSurface.accent,
inactiveTrackColor: color.surface,
inactiveThumbColor: color.onSurface,
activeThumbColor: _isRecurring
? color.onSurface
: color.surface,
),
],
),
Expand Down Expand Up @@ -370,7 +375,7 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
setState(() {
_selectedDays[index] = selected;
if (!_selectedDays.contains(true)) {
_selectedDays[_startDate.weekday - 1] = true;
_selectedDays[_startDate.weekDayEnum.index] = true;
}
});
},
Expand Down Expand Up @@ -583,10 +588,20 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
: _endDate;

final event = CalendarEventData(
date: _startDate,
startDate: _startDate,
endDate: eventEndDate,
endTime: combinedEndTime,
startTime: combinedStartTime,
endTime: combinedEndTime?.hour != null
? TimeOfDay(
hour: combinedEndTime!.hour,
minute: combinedEndTime.minute,
)
: null,
startTime: combinedStartTime?.hour != null
? TimeOfDay(
hour: combinedStartTime!.hour,
minute: combinedStartTime.minute,
)
: null,
color: _color,
title: _titleController.text.trim(),
description: _descriptionController.text.trim(),
Expand All @@ -597,15 +612,15 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
_resetForm();
}

/// Get list of weekdays in indices from the selected days
List<int> get _toWeekdayInIndices {
List<int> selectedIndexes = [];
/// Get list of weekdays from the selected days
List<WeekDays> get _toWeekdayInIndices {
List<WeekDays> selectedWeekdays = [];
for (int i = 0; i < _selectedDays.length; i++) {
if (_selectedDays[i] == true) {
selectedIndexes.add(i);
selectedWeekdays.add(WeekDays.values[i]);
}
}
return selectedIndexes;
return selectedWeekdays;
}

void updateWeekdaysSelection() {
Expand All @@ -615,14 +630,14 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
}
DateTime current = _startDate;
while (current.isBefore(_endDate) || current.isAtSameMomentAs(_endDate)) {
_selectedDays[current.weekday - 1] = true;
_selectedDays[current.weekDayEnum.index] = true;
current = current.add(Duration(days: 1));
}
}

/// Set initial selected week to start date
void _setInitialWeekday() {
final currentWeekday = DateTime.now().weekday - 1;
final currentWeekday = DateTime.now().weekDayEnum.index;
_selectedDays[currentWeekday] = true;
}

Expand All @@ -636,8 +651,18 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {

_startDate = event.date;
_endDate = event.endDate;
_startTime = event.startTime ?? _startTime;
_endTime = event.endTime ?? _endTime;
_startTime = event.startTime != null
? _startDate.copyWith(
hour: event.startTime!.hour,
minute: event.startTime!.minute,
)
: _startDate;
_endTime = event.endTime != null
? _endDate.copyWith(
hour: event.endTime!.hour,
minute: event.endTime!.minute,
)
: _endDate;
_titleController.text = event.title;
_descriptionController.text = event.description ?? '';
_color = event.color; // Set the event color
Expand All @@ -659,7 +684,7 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
// Clear weekdays selection and then set the selected days
_selectedDays = List.filled(7, false);
event.recurrenceSettings!.weekdays.forEach(
(index) => _selectedDays[index] = true,
(week) => _selectedDays[week.index] = true,
);
} else {
_isRecurring = false;
Expand Down
2 changes: 2 additions & 0 deletions example/lib/widgets/calendar_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class _CalendarConfigState extends State<CalendarConfig> {
break;
case CalendarView.week:
viewName = translate.weekView;
case CalendarView.multiDay:
viewName = translate.multidayView;
break;
}
return GestureDetector(
Expand Down
5 changes: 4 additions & 1 deletion example/lib/widgets/calendar_views.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:math';

import 'package:example/widgets/multi_day_view_widget.dart';
import 'package:flutter/material.dart';

import '../enumerations.dart';
Expand All @@ -25,7 +26,9 @@ class CalendarViews extends StatelessWidget {
width: double.infinity,
color: AppColors.grey,
child: Center(
child: view == CalendarView.month
child: view == CalendarView.multiDay
? MultiDayViewWidget(width: width)
: view == CalendarView.month
? MonthViewWidget(width: width)
: view == CalendarView.day
? DayViewWidget(width: width)
Expand Down
3 changes: 2 additions & 1 deletion example/lib/widgets/multi_day_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class MultiDayViewWidget extends StatelessWidget {
daysInView: 3,
width: width,
showLiveTimeLineInAllDays: true,
eventArranger: SideEventArranger(maxWidth: 30),
eventArranger: SideEventArranger(),
backgroundColor: Colors.white,
timeLineWidth: 65,
scrollPhysics: const BouncingScrollPhysics(),
liveTimeIndicatorSettings: LiveTimeIndicatorSettings(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/widgets/week_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WeekViewWidget extends StatelessWidget {
width: width,
showWeekends: true,
showLiveTimeLineInAllDays: true,
eventArranger: SideEventArranger(maxWidth: 30),
eventArranger: SideEventArranger(),
timeLineWidth: 65,
scrollPhysics: const BouncingScrollPhysics(),
liveTimeIndicatorSettings: LiveTimeIndicatorSettings(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version: 1.0.0+1

environment:
sdk: ">=3.10.4 <4.0.0"
flutter: 3.38.5
flutter: 3.38.6

dependencies:
flutter:
Expand Down
Loading