Skip to content

Commit bcecfc5

Browse files
Sahil-SimformPRBaraiya
authored andcommitted
fix : πŸ› Fixed onEventTap in MonthView to ignore when onEventTap is null.(#278)
1 parent 18d6c0e commit bcecfc5

File tree

5 files changed

+53
-28
lines changed

5 files changed

+53
-28
lines changed

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- Adds clear method to `EventController`.
44
- Adds `onEventTapDetails`, `onEventDoubleTapDetails` & `onEventLongTapDetails` gesture recognizers to get tap details. [#390](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/390)
5+
- Fixed `onEventTap` in `MonthView` to ignore when it is
6+
null. [#278](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/278)
57

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

β€Žlib/src/components/month_view_components.dartβ€Ž

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,32 @@ class FilledCell<T extends Object?> extends StatelessWidget {
173173
children: List.generate(
174174
events.length,
175175
(index) => GestureDetector(
176-
onTap: () => onTileTap?.call(events[index], date),
177-
onLongPress: () =>
178-
onTileLongTap?.call(events[index], date),
179-
onDoubleTap: () =>
180-
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-
),
176+
onTap: onTileTap.safeVoidCall(events[index], date),
177+
onLongPress:
178+
onTileLongTap.safeVoidCall(events[index], date),
179+
onDoubleTap:
180+
onTileDoubleTap.safeVoidCall(events[index], date),
181+
onTapUp: onTileTapDetails == null
182+
? null
183+
: (details) => onTileTapDetails?.call(
184+
events[index],
185+
date,
186+
details,
187+
),
188+
onLongPressStart: onTileLongTapDetails == null
189+
? null
190+
: (details) => onTileLongTapDetails?.call(
191+
events[index],
192+
date,
193+
details,
194+
),
195+
onDoubleTapDown: onTileDoubleTapDetails == null
196+
? null
197+
: (details) => onTileDoubleTapDetails?.call(
198+
events[index],
199+
date,
200+
details,
201+
),
198202
child: Container(
199203
decoration: BoxDecoration(
200204
color: events[index].color,

β€Žlib/src/day_view/day_view.dartβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,10 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
656656
/// Default timeline builder this builder will be used if
657657
/// [widget.eventTileBuilder] is null
658658
///
659-
Widget _defaultTimeLineBuilder(date) => DefaultTimeLineMark(
660-
date: date, timeStringBuilder: widget.timeStringBuilder);
659+
Widget _defaultTimeLineBuilder(DateTime date) => DefaultTimeLineMark(
660+
date: date,
661+
timeStringBuilder: widget.timeStringBuilder,
662+
);
661663

662664
/// Default timeline builder. This builder will be used if
663665
/// [widget.eventTileBuilder] is null

β€Žlib/src/extensions.dartβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,20 @@ void debugLog(String message) {
252252
return false;
253253
}(), '');
254254
}
255+
256+
/// For callbacks with one argument
257+
extension NullableCallback1<A> on void Function(A)? {
258+
VoidCallback? safeVoidCall(A a) => this == null ? null : () => this!(a);
259+
}
260+
261+
/// For callbacks with two arguments
262+
extension NullableCallback2<A, B> on void Function(A, B)? {
263+
VoidCallback? safeVoidCall(A a, B b) =>
264+
this == null ? null : () => this!(a, b);
265+
}
266+
267+
/// For callbacks with three arguments
268+
extension NullableCallback3<A, B, C> on void Function(A, B, C)? {
269+
VoidCallback? safeVoidCall(A a, B b, C c) =>
270+
this == null ? null : () => this!(a, b, c);
271+
}

β€Žlib/src/month_view/month_view.dartβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,11 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
582582

583583
/// Default cell builder. Used when [widget.cellBuilder] is null
584584
Widget _defaultCellBuilder(
585-
date,
585+
DateTime date,
586586
List<CalendarEventData<T>> events,
587-
isToday,
588-
isInMonth,
589-
hideDaysNotInMonth,
587+
bool isToday,
588+
bool isInMonth,
589+
bool hideDaysNotInMonth,
590590
) {
591591
if (hideDaysNotInMonth) {
592592
return FilledCell<T>(

0 commit comments

Comments
Β (0)