diff --git a/CHANGELOG.md b/CHANGELOG.md index 982d4db6..e2a15c10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 4984a0ee..f7eb3e61 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example/lib/widgets/month_view_widget.dart b/example/lib/widgets/month_view_widget.dart index d9102d0c..135eda02 100644 --- a/example/lib/widgets/month_view_widget.dart +++ b/example/lib/widgets/month_view_widget.dart @@ -31,10 +31,6 @@ class MonthViewWidget extends StatelessWidget { ), ); }, - onEventLongTap: (event, date) { - SnackBar snackBar = SnackBar(content: Text("on LongTap")); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - }, ); } } diff --git a/lib/src/components/month_view_components.dart b/lib/src/components/month_view_components.dart index a7cd5c5f..9e9d4845 100644 --- a/lib/src/components/month_view_components.dart +++ b/lib/src/components/month_view_components.dart @@ -88,6 +88,12 @@ class FilledCell extends StatelessWidget { /// Called when user double tap on any event tile. final TileTapCallback? onTileDoubleTap; + final TileDoubleTapDetailsCallback? onTileDoubleTapDetails; + + // TODO(Shubham): Add tap doc comments + // TODO(Shubham): Move all callbacks to separate class + final TileTapDetailsCallback? onTileTapDetails; + final TileLongTapDetailsCallback? onTileLongTapDetails; /// defines that [date] is in current month or not. final bool isInMonth; @@ -117,12 +123,15 @@ class FilledCell 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 @@ -161,10 +170,29 @@ class FilledCell 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, diff --git a/lib/src/month_view/month_view.dart b/lib/src/month_view/month_view.dart index 194d4759..96c48eef 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -56,6 +56,11 @@ class MonthView extends StatefulWidget { /// This method will be called when user double taps on event tile. final TileTapCallback? onEventDoubleTap; + final TileTapDetailsCallback? onEventTapDetails; + + final TileLongTapDetailsCallback? onEventLongTapDetails; + final TileDoubleTapDetailsCallback? onEventDoubleTapDetails; + /// Show weekends or not. /// Default value is true. final bool showWeekends; @@ -192,7 +197,11 @@ class MonthView 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, @@ -203,7 +212,6 @@ class MonthView extends StatefulWidget { this.onHeaderTitleTap, this.pagePhysics = const ClampingScrollPhysics(), this.pageViewPhysics, - this.onEventDoubleTap, this.showWeekTileBorder = true, this.hideDaysNotInMonth = false, }) : assert(!(onHeaderTitleTap != null && headerBuilder != null), @@ -574,6 +582,9 @@ class MonthViewState extends State> { onTileTap: widget.onEventTap, onTileDoubleTap: widget.onEventDoubleTap, onTileLongTap: widget.onEventLongTap, + onTileTapDetails: widget.onEventTapDetails, + onTileDoubleTapDetails: widget.onEventDoubleTapDetails, + onTileLongTapDetails: widget.onEventLongTapDetails, dateStringBuilder: widget.dateStringBuilder, hideDaysNotInMonth: hideDaysNotInMonth, ); @@ -585,8 +596,11 @@ class MonthViewState extends State> { 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 diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index 9c51397d..841accc8 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -63,6 +63,25 @@ typedef WeekPageHeaderBuilder = Widget Function( typedef TileTapCallback = void Function( CalendarEventData event, DateTime date); +/// Use this callback to get tap details. +typedef TileTapDetailsCallback = void Function( + CalendarEventData event, + DateTime date, + TapUpDetails? tapDetails, +); + +typedef TileLongTapDetailsCallback = void Function( + CalendarEventData event, + DateTime date, + LongPressStartDetails? longPressDetails, +); + +typedef TileDoubleTapDetailsCallback = void Function( + CalendarEventData event, + DateTime date, + TapDownDetails? doubleTapDetails, +); + typedef CellTapCallback = void Function( List> events, DateTime date);