Skip to content

Commit

Permalink
feat: ✨add on event double tap callback in day, week, month view (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
apurva010 authored May 3, 2024
1 parent fd248d3 commit 1770d66
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- # [1.1.1] (UnReleased)
- Added support for double tapping gestures on any event in day, week, and month view. [#195](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/195)
- Added support for horizontal scroll physics of week and month view page. [#314](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/314)
- Fixed issue related to the live time indicator is that it is not in the correct position when startHour is set for the week and day view. [#346](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/346)
- Fixed issue of onDateTap returns wrong date when startHour is set for week and day view. [#341](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/341)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ 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),
onDateLongPress: (date) => print(date),
headerBuilder: MonthHeader.hidden // To hide month header
Expand Down Expand Up @@ -175,6 +176,7 @@ DayView(
heightPerMinute: 1, // height occupied by 1 minute time span.
eventArranger: SideEventArranger(), // To define how simultaneous events will be arranged.
onEventTap: (events, date) => print(events),
onEventDoubleTap: (events, date) => print(events),
onEventLongTap: (events, date) => print(events),
onDateLongPress: (date) => print(date),
startHour: 5 // To set the first hour displayed (ex: 05:00)
Expand Down Expand Up @@ -206,7 +208,7 @@ WeekView(
heightPerMinute: 1, // height occupied by 1 minute time span.
eventArranger: SideEventArranger(), // To define how simultaneous events will be arranged.
onEventTap: (events, date) => print(events),
onEventTap: (events, date) => print(events),
onEventDoubleTap: (events, date) => print(events),
onDateLongPress: (date) => print(date),
startDay: WeekDays.sunday, // To change the first day of the week.
startHour: 5 // To set the first hour displayed (ex: 05:00)
Expand Down
5 changes: 5 additions & 0 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
/// Called when user long press on event tile.
final CellTapCallback<T>? onTileLongTap;

/// Called when user double tap on any event tile
final CellTapCallback<T>? onTileDoubleTap;

final EventScrollConfiguration scrollNotifier;

/// A widget that display event tiles in day/week view.
Expand All @@ -345,6 +348,7 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
required this.onTileTap,
required this.onTileLongTap,
required this.scrollNotifier,
required this.onTileDoubleTap,
}) : super(key: key);

/// Arrange events and returns list of [Widget] that displays event
Expand All @@ -367,6 +371,7 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
child: GestureDetector(
onLongPress: () => onTileLongTap?.call(events[index].events, date),
onTap: () => onTileTap?.call(events[index].events, date),
onDoubleTap: () => onTileDoubleTap?.call(events[index].events, date),
child: Builder(builder: (context) {
if (scrollNotifier.shouldScroll &&
events[index]
Expand Down
6 changes: 6 additions & 0 deletions lib/src/components/month_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class FilledCell<T extends Object?> extends StatelessWidget {
/// Called when user long press on any event tile.
final TileTapCallback<T>? onTileLongTap;

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

/// defines that [date] is in current month or not.
final bool isInMonth;

Expand Down Expand Up @@ -118,6 +121,7 @@ class FilledCell<T extends Object?> extends StatelessWidget {
this.titleColor = Constants.black,
this.highlightedTitleColor = Constants.white,
this.dateStringBuilder,
this.onTileDoubleTap,
}) : super(key: key);

@override
Expand Down Expand Up @@ -162,6 +166,8 @@ class FilledCell<T extends Object?> extends StatelessWidget {
onTileTap?.call(events[index], events[index].date),
onLongPress: () => onTileLongTap?.call(
events[index], events[index].date),
onDoubleTap: () => onTileDoubleTap?.call(
events[index], events[index].date),
child: Container(
decoration: BoxDecoration(
color: events[index].color,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
/// Called when user long press on event tile.
final CellTapCallback<T>? onTileLongTap;

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

/// Called when user long press on calendar.
final DatePressCallback? onDateLongPress;

Expand Down Expand Up @@ -153,6 +156,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
required this.startHour,
required this.quarterHourIndicatorSettings,
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
}) : super(key: key);

@override
Expand Down Expand Up @@ -233,6 +237,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
height: height,
date: date,
onTileLongTap: onTileLongTap,
onTileDoubleTap: onTileDoubleTap,
onTileTap: onTileTap,
eventArranger: eventArranger,
events: controller.getEventsOnDay(
Expand Down
5 changes: 5 additions & 0 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ class DayView<T extends Object?> extends StatefulWidget {
/// This method will be called when user long press on event tile.
final CellTapCallback<T>? onEventLongTap;

/// This method will be called when user double taps on event tile.
final CellTapCallback<T>? onEventDoubleTap;

/// This method will be called when user long press on calendar.
final DatePressCallback? onDateLongPress;

Expand Down Expand Up @@ -267,6 +270,7 @@ class DayView<T extends Object?> extends StatefulWidget {
this.startDuration = const Duration(hours: 0),
this.onHeaderTitleTap,
this.emulateVerticalOffsetBy = 0,
this.onEventDoubleTap,
}) : assert(!(onHeaderTitleTap != null && dayTitleBuilder != null),
"can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"),
assert(timeLineOffset >= 0,
Expand Down Expand Up @@ -458,6 +462,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
onTileLongTap: widget.onEventLongTap,
onDateLongPress: widget.onDateLongPress,
onDateTap: widget.onDateTap,
onTileDoubleTap: widget.onEventDoubleTap,
showLiveLine: widget.showLiveTimeLineInAllDays ||
date.compareWithoutTime(DateTime.now()),
timeLineOffset: widget.timeLineOffset,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// This function will only work if [cellBuilder] is null.
final TileTapCallback<T>? onEventLongTap;

/// This method will be called when user double taps on event tile.
final TileTapCallback<T>? onEventDoubleTap;

/// Builds the name of the weeks.
///
/// Used default week builder if null.
Expand Down Expand Up @@ -190,6 +193,7 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.onHeaderTitleTap,
this.pagePhysics = const ClampingScrollPhysics(),
this.pageViewPhysics,
this.onEventDoubleTap,
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
"can't use [onHeaderTitleTap] & [headerBuilder] simultaneously"),
super(key: key);
Expand Down Expand Up @@ -531,6 +535,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
dateStringBuilder: widget.dateStringBuilder,
onTileDoubleTap: widget.onEventDoubleTap,
);
}

Expand Down
87 changes: 46 additions & 41 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
/// Called when user long press on event tile.
final CellTapCallback<T>? onTileLongTap;

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

/// Defines which days should be displayed in one week.
///
/// By default all the days will be visible.
Expand Down Expand Up @@ -139,47 +142,48 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
final double emulateVerticalOffsetBy;

/// A single page for week view.
const InternalWeekViewPage(
{Key? key,
required this.showVerticalLine,
required this.weekTitleHeight,
required this.weekDayBuilder,
required this.weekNumberBuilder,
required this.width,
required this.dates,
required this.eventTileBuilder,
required this.controller,
required this.timeLineBuilder,
required this.hourIndicatorSettings,
required this.hourLinePainter,
required this.halfHourIndicatorSettings,
required this.quarterHourIndicatorSettings,
required this.showLiveLine,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute,
required this.timeLineWidth,
required this.timeLineOffset,
required this.height,
required this.hourHeight,
required this.eventArranger,
required this.verticalLineOffset,
required this.weekTitleWidth,
required this.scrollController,
required this.onTileTap,
required this.onTileLongTap,
required this.onDateLongPress,
required this.onDateTap,
required this.weekDays,
required this.minuteSlotSize,
required this.scrollConfiguration,
required this.startHour,
required this.fullDayEventBuilder,
required this.weekDetectorBuilder,
required this.showWeekDayAtBottom,
required this.showHalfHours,
required this.showQuarterHours,
required this.emulateVerticalOffsetBy})
: super(key: key);
const InternalWeekViewPage({
Key? key,
required this.showVerticalLine,
required this.weekTitleHeight,
required this.weekDayBuilder,
required this.weekNumberBuilder,
required this.width,
required this.dates,
required this.eventTileBuilder,
required this.controller,
required this.timeLineBuilder,
required this.hourIndicatorSettings,
required this.hourLinePainter,
required this.halfHourIndicatorSettings,
required this.quarterHourIndicatorSettings,
required this.showLiveLine,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute,
required this.timeLineWidth,
required this.timeLineOffset,
required this.height,
required this.hourHeight,
required this.eventArranger,
required this.verticalLineOffset,
required this.weekTitleWidth,
required this.scrollController,
required this.onTileTap,
required this.onTileLongTap,
required this.onDateLongPress,
required this.onDateTap,
required this.weekDays,
required this.minuteSlotSize,
required this.scrollConfiguration,
required this.startHour,
required this.fullDayEventBuilder,
required this.weekDetectorBuilder,
required this.showWeekDayAtBottom,
required this.showHalfHours,
required this.showQuarterHours,
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -328,6 +332,7 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
date: filteredDates[index],
onTileTap: onTileTap,
onTileLongTap: onTileLongTap,
onTileDoubleTap: onTileDoubleTap,
width: weekTitleWidth,
eventArranger: eventArranger,
eventTileBuilder: eventTileBuilder,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// Called when user long press on event tile.
final CellTapCallback<T>? onEventLongTap;

/// Called when user double taps on any event tile.
final CellTapCallback<T>? onEventDoubleTap;

/// Show weekends or not
///
/// Default value is true.
Expand Down Expand Up @@ -278,6 +281,7 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.emulateVerticalOffsetBy = 0,
this.showWeekDayAtBottom = false,
this.pageViewPhysics,
this.onEventDoubleTap,
}) : assert(!(onHeaderTitleTap != null && weekPageHeaderBuilder != null),
"can't use [onHeaderTitleTap] & [weekPageHeaderBuilder] simultaneously"),
assert((timeLineOffset) >= 0,
Expand Down Expand Up @@ -486,6 +490,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
onTileLongTap: widget.onEventLongTap,
onDateLongPress: widget.onDateLongPress,
onDateTap: widget.onDateTap,
onTileDoubleTap: widget.onEventDoubleTap,
eventTileBuilder: _eventTileBuilder,
heightPerMinute: widget.heightPerMinute,
hourIndicatorSettings: _hourIndicatorSettings,
Expand Down

0 comments on commit 1770d66

Please sign in to comment.