Skip to content

Commit

Permalink
feat: Fixes issue #390: ✨ Update tap events in month view
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Jan 7, 2025
1 parent 469cc29 commit b910a30
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [1.4.1 - Unreleased]

- Adds clear method to `EventController`.
- Updates `onEventTap`, `onEventDoubleTap` & `onEventLongTap` gesture recognizers to get tap details. [#390](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/390)

# [1.4.0 - 7 Jan 2025](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.4.0)

Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,30 @@ MonthView(
},
startDay: WeekDays.sunday, // To change the first day of the week.
// This callback will only work if cellBuilder is null.
onEventTap: (event, date) => print(event),
onEventDoubleTap: (events, date) => print(events),
onEventLongTap: (event, date) => print(event),
onEventTap: (
event,
date, {
tapDetails,
longPressDetails,
doubleTapDetails,
}) =>
print(event),
onEventDoubleTap: (
event,
date, {
tapDetails,
longPressDetails,
doubleTapDetails,
}) =>
print(event),
onEventLongTap: (
event,
date, {
tapDetails,
longPressDetails,
doubleTapDetails,
}) =>
print(event),
onDateLongPress: (date) => print(date),
headerBuilder: MonthHeader.hidden, // To hide month header
showWeekTileBorder: false, // To show or hide header border
Expand Down
16 changes: 14 additions & 2 deletions example/lib/widgets/month_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ class MonthViewWidget extends StatelessWidget {
showWeekends: true,
startDay: WeekDays.friday,
useAvailableVerticalSpace: true,
onEventTap: (event, date) {
onEventTap: (
event,
date, {
tapDetails,
longPressDetails,
doubleTapDetails,
}) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => DetailsPage(
Expand All @@ -31,7 +37,13 @@ class MonthViewWidget extends StatelessWidget {
),
);
},
onEventLongTap: (event, date) {
onEventLongTap: (
event,
date, {
tapDetails,
longPressDetails,
doubleTapDetails,
}) {
SnackBar snackBar = SnackBar(content: Text("on LongTap"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
Expand Down
20 changes: 15 additions & 5 deletions lib/src/components/month_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,21 @@ class FilledCell<T extends Object?> extends StatelessWidget {
children: List.generate(
events.length,
(index) => GestureDetector(
onTap: () => onTileTap?.call(events[index], date),
onLongPress: () =>
onTileLongTap?.call(events[index], date),
onDoubleTap: () =>
onTileDoubleTap?.call(events[index], date),
onTapUp: (details) => onTileTap?.call(
events[index],
date,
tapDetails: details,
),
onLongPressStart: (details) => onTileLongTap?.call(
events[index],
date,
longPressDetails: details,
),
onDoubleTapDown: (details) => onTileDoubleTap?.call(
events[index],
date,
doubleTapDetails: details,
),
child: Container(
decoration: BoxDecoration(
color: events[index].color,
Expand Down
7 changes: 6 additions & 1 deletion lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ typedef WeekPageHeaderBuilder = Widget Function(
);

typedef TileTapCallback<T extends Object?> = void Function(
CalendarEventData<T> event, DateTime date);
CalendarEventData<T> event,
DateTime date, {
TapUpDetails? tapDetails,
LongPressStartDetails? longPressDetails,
TapDownDetails? doubleTapDetails,
});

typedef CellTapCallback<T extends Object?> = void Function(
List<CalendarEventData<T>> events, DateTime date);
Expand Down

0 comments on commit b910a30

Please sign in to comment.