Skip to content

Commit

Permalink
feat: Fixes issue #390: ✨ Add tap events in month view
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Jan 24, 2025
1 parent 469cc29 commit 4e4e5c7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ MonthView(
onEventTap: (event, date) => print(event),
onEventDoubleTap: (events, date) => print(events),
onEventLongTap: (event, date) => print(event),
onEventTapDetails: (event, data, tapDetails) => print(events),
onEventDoubleTapDetails: (event, data, details) => print(events),
onEventLongTapDetails: (event, data, tapDetails) => print(events),
onDateLongPress: (date) => print(date),
headerBuilder: MonthHeader.hidden, // To hide month header
showWeekTileBorder: false, // To show or hide header border
Expand Down
4 changes: 0 additions & 4 deletions example/lib/widgets/month_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class MonthViewWidget extends StatelessWidget {
),
);
},
onEventLongTap: (event, date) {
SnackBar snackBar = SnackBar(content: Text("on LongTap"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
);
}
}
34 changes: 31 additions & 3 deletions lib/src/components/month_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class FilledCell<T extends Object?> extends StatelessWidget {

/// Called when user double tap on any event tile.
final TileTapCallback<T>? onTileDoubleTap;
final TileDoubleTapDetailsCallback<T>? onTileDoubleTapDetails;

// TODO(Shubham): Add tap doc comments
// TODO(Shubham): Move all callbacks to separate class
final TileTapDetailsCallback<T>? onTileTapDetails;
final TileLongTapDetailsCallback<T>? onTileLongTapDetails;

/// defines that [date] is in current month or not.
final bool isInMonth;
Expand Down Expand Up @@ -117,12 +123,15 @@ class FilledCell<T extends Object?> extends StatelessWidget {
this.highlightColor = Colors.blue,
this.onTileTap,
this.onTileLongTap,
this.onTileDoubleTap,
this.onTileTapDetails,
this.onTileDoubleTapDetails,
this.onTileLongTapDetails,
this.tileColor = Colors.blue,
this.highlightRadius = 11,
this.titleColor = Constants.black,
this.highlightedTitleColor = Constants.white,
this.dateStringBuilder,
this.onTileDoubleTap,
}) : super(key: key);

@override
Expand Down Expand Up @@ -161,10 +170,29 @@ class FilledCell<T extends Object?> extends StatelessWidget {
events.length,
(index) => GestureDetector(
onTap: () => onTileTap?.call(events[index], date),
onLongPress: () =>
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,
),
onLongPress: () => onTileLongTap?.call(
events[index],
date,
),
onDoubleTapDown: (details) =>
onTileDoubleTapDetails?.call(
events[index],
date,
details,
),
child: Container(
decoration: BoxDecoration(
color: events[index].color,
Expand Down
16 changes: 15 additions & 1 deletion lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// This method will be called when user double taps on event tile.
final TileTapCallback<T>? onEventDoubleTap;

final TileTapDetailsCallback<T>? onEventTapDetails;

final TileLongTapDetailsCallback<T>? onEventLongTapDetails;
final TileDoubleTapDetailsCallback<T>? onEventDoubleTapDetails;

/// Show weekends or not.
/// Default value is true.
final bool showWeekends;
Expand Down Expand Up @@ -192,7 +197,11 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.onPageChange,
this.onCellTap,
this.onEventTap,
this.onEventLongTapDetails,
this.onEventLongTap,
this.onEventTapDetails,
this.onEventDoubleTap,
this.onEventDoubleTapDetails,
this.onDateLongPress,
this.startDay = WeekDays.monday,
this.headerStringBuilder,
Expand All @@ -203,7 +212,6 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.onHeaderTitleTap,
this.pagePhysics = const ClampingScrollPhysics(),
this.pageViewPhysics,
this.onEventDoubleTap,
this.showWeekTileBorder = true,
this.hideDaysNotInMonth = false,
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
Expand Down Expand Up @@ -574,6 +582,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,8 +596,11 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
events: events,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
onTileTapDetails: widget.onEventTapDetails,
onTileDoubleTapDetails: widget.onEventDoubleTapDetails,
dateStringBuilder: widget.dateStringBuilder,
onTileDoubleTap: widget.onEventDoubleTap,
onTileLongTapDetails: widget.onEventLongTapDetails,
hideDaysNotInMonth: hideDaysNotInMonth,
titleColor: isInMonth
? Theme.of(context).colorScheme.onPrimaryContainer
Expand Down
19 changes: 19 additions & 0 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ typedef WeekPageHeaderBuilder = Widget Function(
typedef TileTapCallback<T extends Object?> = void Function(
CalendarEventData<T> event, DateTime date);

/// Use this callback to get tap details.
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 4e4e5c7

Please sign in to comment.