Skip to content

Commit 2759702

Browse files
authored
Merge pull request #449 from SimformSolutionsPvtLtd/feature/change_tile_tap
feat: Fixes issue #390: ✨ Add tap details callback in month view
2 parents 469cc29 + b37b779 commit 2759702

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# [1.4.1 - Unreleased]
22

33
- Adds clear method to `EventController`.
4+
- Adds `onEventTapDetails`, `onEventDoubleTapDetails` & `onEventLongTapDetails` gesture recognizers to get tap details. [#390](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/390)
45

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

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ MonthView(
153153
},
154154
startDay: WeekDays.sunday, // To change the first day of the week.
155155
// This callback will only work if cellBuilder is null.
156-
onEventTap: (event, date) => print(event),
157-
onEventDoubleTap: (events, date) => print(events),
158-
onEventLongTap: (event, date) => print(event),
156+
onEventTap: (event, data) => print('on tap'),
157+
onEventTapDetails: (event, data, details) => print('on tap details'),
158+
onEventDoubleTap: (event, data) => print('on double tap'),
159+
onEventDoubleTapDetails: (event, data, details) =>
160+
print('on double details'),
161+
onEventLongTap: (event, data) => print('on long tap'),
162+
onEventLongTapDetails: (event, data, details) =>
163+
print('on long tap details'),
159164
onDateLongPress: (date) => print(date),
160165
headerBuilder: MonthHeader.hidden, // To hide month header
161166
showWeekTileBorder: false, // To show or hide header border

lib/src/components/month_view_components.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class FilledCell<T extends Object?> extends StatelessWidget {
8080
/// Color for event tile.
8181
final Color tileColor;
8282

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

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

93+
/// Similar to [onTileTap] with additional tap details callback.
94+
final TileTapDetailsCallback<T>? onTileTapDetails;
95+
96+
/// Similar to [onTileDoubleTap] with additional tap details callback.
97+
final TileDoubleTapDetailsCallback<T>? onTileDoubleTapDetails;
98+
99+
/// Similar to [onTileLongTap] with additional tap details callback.
100+
final TileLongTapDetailsCallback<T>? onTileLongTapDetails;
101+
92102
/// defines that [date] is in current month or not.
93103
final bool isInMonth;
94104

@@ -117,6 +127,9 @@ class FilledCell<T extends Object?> extends StatelessWidget {
117127
this.highlightColor = Colors.blue,
118128
this.onTileTap,
119129
this.onTileLongTap,
130+
this.onTileTapDetails,
131+
this.onTileDoubleTapDetails,
132+
this.onTileLongTapDetails,
120133
this.tileColor = Colors.blue,
121134
this.highlightRadius = 11,
122135
this.titleColor = Constants.black,
@@ -165,6 +178,23 @@ class FilledCell<T extends Object?> extends StatelessWidget {
165178
onTileLongTap?.call(events[index], date),
166179
onDoubleTap: () =>
167180
onTileDoubleTap?.call(events[index], date),
181+
onTapUp: (details) => onTileTapDetails?.call(
182+
events[index],
183+
date,
184+
details,
185+
),
186+
onLongPressStart: (details) =>
187+
onTileLongTapDetails?.call(
188+
events[index],
189+
date,
190+
details,
191+
),
192+
onDoubleTapDown: (details) =>
193+
onTileDoubleTapDetails?.call(
194+
events[index],
195+
date,
196+
details,
197+
),
168198
child: Container(
169199
decoration: BoxDecoration(
170200
color: events[index].color,

lib/src/month_view/month_view.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,30 @@ class MonthView<T extends Object?> extends StatefulWidget {
5353
/// This function will only work if [cellBuilder] is null.
5454
final TileTapCallback<T>? onEventLongTap;
5555

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

62+
/// This function will be called when user will tap on a single event
63+
/// tile inside a cell and gives additional details offset.
64+
///
65+
/// This function will only work if [cellBuilder] is null.
66+
final TileTapDetailsCallback<T>? onEventTapDetails;
67+
68+
/// This function will be called when user will long press on a single event
69+
/// tile inside a cell and gives additional details offset.
70+
///
71+
/// This function will only work if [cellBuilder] is null.
72+
final TileLongTapDetailsCallback<T>? onEventLongTapDetails;
73+
74+
/// This function will be called when user will double tap on a single event
75+
/// tile inside a cell and gives additional details offset.
76+
///
77+
/// This function will only work if [cellBuilder] is null.
78+
final TileDoubleTapDetailsCallback<T>? onEventDoubleTapDetails;
79+
5980
/// Show weekends or not.
6081
/// Default value is true.
6182
final bool showWeekends;
@@ -192,7 +213,10 @@ class MonthView<T extends Object?> extends StatefulWidget {
192213
this.onPageChange,
193214
this.onCellTap,
194215
this.onEventTap,
216+
this.onEventTapDetails,
195217
this.onEventLongTap,
218+
this.onEventLongTapDetails,
219+
this.onEventDoubleTapDetails,
196220
this.onDateLongPress,
197221
this.startDay = WeekDays.monday,
198222
this.headerStringBuilder,
@@ -574,6 +598,9 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
574598
onTileTap: widget.onEventTap,
575599
onTileDoubleTap: widget.onEventDoubleTap,
576600
onTileLongTap: widget.onEventLongTap,
601+
onTileTapDetails: widget.onEventTapDetails,
602+
onTileDoubleTapDetails: widget.onEventDoubleTapDetails,
603+
onTileLongTapDetails: widget.onEventLongTapDetails,
577604
dateStringBuilder: widget.dateStringBuilder,
578605
hideDaysNotInMonth: hideDaysNotInMonth,
579606
);
@@ -585,6 +612,9 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
585612
events: events,
586613
onTileTap: widget.onEventTap,
587614
onTileLongTap: widget.onEventLongTap,
615+
onTileTapDetails: widget.onEventTapDetails,
616+
onTileDoubleTapDetails: widget.onEventDoubleTapDetails,
617+
onTileLongTapDetails: widget.onEventLongTapDetails,
588618
dateStringBuilder: widget.dateStringBuilder,
589619
onTileDoubleTap: widget.onEventDoubleTap,
590620
hideDaysNotInMonth: hideDaysNotInMonth,

lib/src/typedefs.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ typedef WeekPageHeaderBuilder = Widget Function(
6363
typedef TileTapCallback<T extends Object?> = void Function(
6464
CalendarEventData<T> event, DateTime date);
6565

66+
typedef TileTapDetailsCallback<T extends Object?> = void Function(
67+
CalendarEventData<T> event,
68+
DateTime date,
69+
TapUpDetails? tapDetails,
70+
);
71+
72+
typedef TileLongTapDetailsCallback<T extends Object?> = void Function(
73+
CalendarEventData<T> event,
74+
DateTime date,
75+
LongPressStartDetails? longPressDetails,
76+
);
77+
78+
typedef TileDoubleTapDetailsCallback<T extends Object?> = void Function(
79+
CalendarEventData<T> event,
80+
DateTime date,
81+
TapDownDetails? doubleTapDetails,
82+
);
83+
6684
typedef CellTapCallback<T extends Object?> = void Function(
6785
List<CalendarEventData<T>> events, DateTime date);
6886

0 commit comments

Comments
 (0)