From b910a30bc1294f9e9f14a017b91a95df8d1f6109 Mon Sep 17 00:00:00 2001 From: Shubham Jitiya Date: Mon, 6 Jan 2025 18:35:13 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20Fixes=20issue=20#390:=20=E2=9C=A8=20Upd?= =?UTF-8?q?ate=20tap=20events=20in=20month=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + README.md | 27 ++++++++++++++++--- example/lib/widgets/month_view_widget.dart | 16 +++++++++-- lib/src/components/month_view_components.dart | 20 ++++++++++---- lib/src/typedefs.dart | 7 ++++- 5 files changed, 60 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 982d4db6..af7b47a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # [1.4.1 - Unreleased] - Adds clear method to `EventController`. +- Updates `onEventTap`, `onEventDoubleTap` & `onEventLongTap` 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..2565defb 100644 --- a/README.md +++ b/README.md @@ -153,9 +153,30 @@ MonthView( }, startDay: WeekDays.sunday, // To change the first day of the week. // This callback will only work if cellBuilder is null. - onEventTap: (event, date) => print(event), - onEventDoubleTap: (events, date) => print(events), - onEventLongTap: (event, date) => print(event), + onEventTap: ( + event, + date, { + tapDetails, + longPressDetails, + doubleTapDetails, + }) => + print(event), + onEventDoubleTap: ( + event, + date, { + tapDetails, + longPressDetails, + doubleTapDetails, + }) => + print(event), + onEventLongTap: ( + event, + date, { + tapDetails, + longPressDetails, + doubleTapDetails, + }) => + print(event), 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..da439462 100644 --- a/example/lib/widgets/month_view_widget.dart +++ b/example/lib/widgets/month_view_widget.dart @@ -21,7 +21,13 @@ class MonthViewWidget extends StatelessWidget { showWeekends: true, startDay: WeekDays.friday, useAvailableVerticalSpace: true, - onEventTap: (event, date) { + onEventTap: ( + event, + date, { + tapDetails, + longPressDetails, + doubleTapDetails, + }) { Navigator.of(context).push( MaterialPageRoute( builder: (_) => DetailsPage( @@ -31,7 +37,13 @@ class MonthViewWidget extends StatelessWidget { ), ); }, - onEventLongTap: (event, date) { + onEventLongTap: ( + event, + date, { + tapDetails, + longPressDetails, + doubleTapDetails, + }) { 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..3e5ddcce 100644 --- a/lib/src/components/month_view_components.dart +++ b/lib/src/components/month_view_components.dart @@ -160,11 +160,21 @@ class FilledCell extends StatelessWidget { children: List.generate( events.length, (index) => GestureDetector( - onTap: () => onTileTap?.call(events[index], date), - onLongPress: () => - onTileLongTap?.call(events[index], date), - onDoubleTap: () => - onTileDoubleTap?.call(events[index], date), + onTapUp: (details) => onTileTap?.call( + events[index], + date, + tapDetails: details, + ), + onLongPressStart: (details) => onTileLongTap?.call( + events[index], + date, + longPressDetails: details, + ), + onDoubleTapDown: (details) => onTileDoubleTap?.call( + events[index], + date, + doubleTapDetails: details, + ), child: Container( decoration: BoxDecoration( color: events[index].color, diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index 9c51397d..ebdf6b81 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -61,7 +61,12 @@ typedef WeekPageHeaderBuilder = Widget Function( ); typedef TileTapCallback = void Function( - CalendarEventData event, DateTime date); + CalendarEventData event, + DateTime date, { + TapUpDetails? tapDetails, + LongPressStartDetails? longPressDetails, + TapDownDetails? doubleTapDetails, +}); typedef CellTapCallback = void Function( List> events, DateTime date);