Skip to content

Commit

Permalink
Merge pull request #449 from SimformSolutionsPvtLtd/feature/change_ti…
Browse files Browse the repository at this point in the history
…le_tap

feat: Fixes issue #390: ✨ Add tap details callback in month view
  • Loading branch information
PRBaraiya authored Jan 29, 2025
2 parents 469cc29 + b37b779 commit 2759702
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 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`.
- Adds `onEventTapDetails`, `onEventDoubleTapDetails` & `onEventLongTapDetails` 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
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ 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, data) => print('on tap'),
onEventTapDetails: (event, data, details) => print('on tap details'),
onEventDoubleTap: (event, data) => print('on double tap'),
onEventDoubleTapDetails: (event, data, details) =>
print('on double details'),
onEventLongTap: (event, data) => print('on long tap'),
onEventLongTapDetails: (event, data, details) =>
print('on long tap details'),
onDateLongPress: (date) => print(date),
headerBuilder: MonthHeader.hidden, // To hide month header
showWeekTileBorder: false, // To show or hide header border
Expand Down
30 changes: 30 additions & 0 deletions lib/src/components/month_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class FilledCell<T extends Object?> extends StatelessWidget {
/// Color for event tile.
final Color tileColor;

// TODO(Shubham): Move all callbacks to separate class
/// Called when user taps on any event tile.
final TileTapCallback<T>? onTileTap;

Expand All @@ -89,6 +90,15 @@ class FilledCell<T extends Object?> extends StatelessWidget {
/// Called when user double tap on any event tile.
final TileTapCallback<T>? onTileDoubleTap;

/// Similar to [onTileTap] with additional tap details callback.
final TileTapDetailsCallback<T>? onTileTapDetails;

/// Similar to [onTileDoubleTap] with additional tap details callback.
final TileDoubleTapDetailsCallback<T>? onTileDoubleTapDetails;

/// Similar to [onTileLongTap] with additional tap details callback.
final TileLongTapDetailsCallback<T>? onTileLongTapDetails;

/// defines that [date] is in current month or not.
final bool isInMonth;

Expand Down Expand Up @@ -117,6 +127,9 @@ class FilledCell<T extends Object?> extends StatelessWidget {
this.highlightColor = Colors.blue,
this.onTileTap,
this.onTileLongTap,
this.onTileTapDetails,
this.onTileDoubleTapDetails,
this.onTileLongTapDetails,
this.tileColor = Colors.blue,
this.highlightRadius = 11,
this.titleColor = Constants.black,
Expand Down Expand Up @@ -165,6 +178,23 @@ class FilledCell<T extends Object?> extends StatelessWidget {
onTileLongTap?.call(events[index], date),
onDoubleTap: () =>
onTileDoubleTap?.call(events[index], date),
onTapUp: (details) => onTileTapDetails?.call(
events[index],
date,
details,
),
onLongPressStart: (details) =>
onTileLongTapDetails?.call(
events[index],
date,
details,
),
onDoubleTapDown: (details) =>
onTileDoubleTapDetails?.call(
events[index],
date,
details,
),
child: Container(
decoration: BoxDecoration(
color: events[index].color,
Expand Down
32 changes: 31 additions & 1 deletion lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,30 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// This function will only work if [cellBuilder] is null.
final TileTapCallback<T>? onEventLongTap;

/// This method will be called when user double taps on event tile.
/// This function will be called when user will double tap on a single event
/// tile inside a cell.
///
/// This function will only work if [cellBuilder] is null.
final TileTapCallback<T>? onEventDoubleTap;

/// This function will be called when user will tap on a single event
/// tile inside a cell and gives additional details offset.
///
/// This function will only work if [cellBuilder] is null.
final TileTapDetailsCallback<T>? onEventTapDetails;

/// This function will be called when user will long press on a single event
/// tile inside a cell and gives additional details offset.
///
/// This function will only work if [cellBuilder] is null.
final TileLongTapDetailsCallback<T>? onEventLongTapDetails;

/// This function will be called when user will double tap on a single event
/// tile inside a cell and gives additional details offset.
///
/// This function will only work if [cellBuilder] is null.
final TileDoubleTapDetailsCallback<T>? onEventDoubleTapDetails;

/// Show weekends or not.
/// Default value is true.
final bool showWeekends;
Expand Down Expand Up @@ -192,7 +213,10 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.onPageChange,
this.onCellTap,
this.onEventTap,
this.onEventTapDetails,
this.onEventLongTap,
this.onEventLongTapDetails,
this.onEventDoubleTapDetails,
this.onDateLongPress,
this.startDay = WeekDays.monday,
this.headerStringBuilder,
Expand Down Expand Up @@ -574,6 +598,9 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
onTileTap: widget.onEventTap,
onTileDoubleTap: widget.onEventDoubleTap,
onTileLongTap: widget.onEventLongTap,
onTileTapDetails: widget.onEventTapDetails,
onTileDoubleTapDetails: widget.onEventDoubleTapDetails,
onTileLongTapDetails: widget.onEventLongTapDetails,
dateStringBuilder: widget.dateStringBuilder,
hideDaysNotInMonth: hideDaysNotInMonth,
);
Expand All @@ -585,6 +612,9 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
events: events,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
onTileTapDetails: widget.onEventTapDetails,
onTileDoubleTapDetails: widget.onEventDoubleTapDetails,
onTileLongTapDetails: widget.onEventLongTapDetails,
dateStringBuilder: widget.dateStringBuilder,
onTileDoubleTap: widget.onEventDoubleTap,
hideDaysNotInMonth: hideDaysNotInMonth,
Expand Down
18 changes: 18 additions & 0 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ typedef WeekPageHeaderBuilder = Widget Function(
typedef TileTapCallback<T extends Object?> = void Function(
CalendarEventData<T> event, DateTime date);

typedef TileTapDetailsCallback<T extends Object?> = void Function(
CalendarEventData<T> event,
DateTime date,
TapUpDetails? tapDetails,
);

typedef TileLongTapDetailsCallback<T extends Object?> = void Function(
CalendarEventData<T> event,
DateTime date,
LongPressStartDetails? longPressDetails,
);

typedef TileDoubleTapDetailsCallback<T extends Object?> = void Function(
CalendarEventData<T> event,
DateTime date,
TapDownDetails? doubleTapDetails,
);

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

Expand Down

0 comments on commit 2759702

Please sign in to comment.