Skip to content

Commit e7d035b

Browse files
author
Shubham Jitiya
committed
feat: Fixes issue #390: ✨ Add tap details callback in month view
1 parent 469cc29 commit e7d035b

File tree

6 files changed

+96
-12
lines changed

6 files changed

+96
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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)
5+
- Fixes issue `doubleTap` not working
46

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

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

example/lib/widgets/month_view_widget.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class MonthViewWidget extends StatelessWidget {
3131
),
3232
);
3333
},
34-
onEventLongTap: (event, date) {
35-
SnackBar snackBar = SnackBar(content: Text("on LongTap"));
36-
ScaffoldMessenger.of(context).showSnackBar(snackBar);
37-
},
3834
);
3935
}
4036
}

lib/src/components/month_view_components.dart

Lines changed: 35 additions & 3 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,12 +127,15 @@ class FilledCell<T extends Object?> extends StatelessWidget {
117127
this.highlightColor = Colors.blue,
118128
this.onTileTap,
119129
this.onTileLongTap,
130+
this.onTileDoubleTap,
131+
this.onTileTapDetails,
132+
this.onTileDoubleTapDetails,
133+
this.onTileLongTapDetails,
120134
this.tileColor = Colors.blue,
121135
this.highlightRadius = 11,
122136
this.titleColor = Constants.black,
123137
this.highlightedTitleColor = Constants.white,
124138
this.dateStringBuilder,
125-
this.onTileDoubleTap,
126139
}) : super(key: key);
127140

128141
@override
@@ -161,10 +174,29 @@ class FilledCell<T extends Object?> extends StatelessWidget {
161174
events.length,
162175
(index) => GestureDetector(
163176
onTap: () => onTileTap?.call(events[index], date),
164-
onLongPress: () =>
165-
onTileLongTap?.call(events[index], date),
177+
onLongPress: () => onTileLongTap?.call(
178+
events[index],
179+
date,
180+
),
166181
onDoubleTap: () =>
167182
onTileDoubleTap?.call(events[index], date),
183+
onTapUp: (details) => onTileTapDetails?.call(
184+
events[index],
185+
date,
186+
details,
187+
),
188+
onLongPressStart: (details) =>
189+
onTileLongTapDetails?.call(
190+
events[index],
191+
date,
192+
details,
193+
),
194+
onDoubleTapDown: (details) =>
195+
onTileDoubleTapDetails?.call(
196+
events[index],
197+
date,
198+
details,
199+
),
168200
child: Container(
169201
decoration: BoxDecoration(
170202
color: events[index].color,

lib/src/month_view/month_view.dart

Lines changed: 32 additions & 2 deletions
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,11 @@ 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.onEventDoubleTap,
220+
this.onEventDoubleTapDetails,
196221
this.onDateLongPress,
197222
this.startDay = WeekDays.monday,
198223
this.headerStringBuilder,
@@ -203,7 +228,6 @@ class MonthView<T extends Object?> extends StatefulWidget {
203228
this.onHeaderTitleTap,
204229
this.pagePhysics = const ClampingScrollPhysics(),
205230
this.pageViewPhysics,
206-
this.onEventDoubleTap,
207231
this.showWeekTileBorder = true,
208232
this.hideDaysNotInMonth = false,
209233
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
@@ -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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ typedef WeekPageHeaderBuilder = Widget Function(
6363
typedef TileTapCallback<T extends Object?> = void Function(
6464
CalendarEventData<T> event, DateTime date);
6565

66+
/// Use this callback to get tap details.
67+
typedef TileTapDetailsCallback<T extends Object?> = void Function(
68+
CalendarEventData<T> event,
69+
DateTime date,
70+
TapUpDetails? tapDetails,
71+
);
72+
73+
typedef TileLongTapDetailsCallback<T extends Object?> = void Function(
74+
CalendarEventData<T> event,
75+
DateTime date,
76+
LongPressStartDetails? longPressDetails,
77+
);
78+
79+
typedef TileDoubleTapDetailsCallback<T extends Object?> = void Function(
80+
CalendarEventData<T> event,
81+
DateTime date,
82+
TapDownDetails? doubleTapDetails,
83+
);
84+
6685
typedef CellTapCallback<T extends Object?> = void Function(
6786
List<CalendarEventData<T>> events, DateTime date);
6887

0 commit comments

Comments
 (0)