Skip to content

Commit

Permalink
feat: Added support for event long-press method execution (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitbhoite authored May 1, 2024
1 parent 0858017 commit fd248d3
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 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),
onEventLongTap: (event, date) => print(event),
onDateLongPress: (date) => print(date),
headerBuilder: MonthHeader.hidden // To hide month header
);
Expand All @@ -174,6 +175,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),
onEventLongTap: (events, date) => print(events),
onDateLongPress: (date) => print(date),
startHour: 5 // To set the first hour displayed (ex: 05:00)
hourLinePainter: (lineColor, lineHeight, offset, minuteHeight, showVerticalLine, verticalLineOffset) {
Expand Down Expand Up @@ -204,6 +206,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),
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
4 changes: 4 additions & 0 deletions example/lib/widgets/day_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class DayViewWidget extends StatelessWidget {
),
);
},
onEventLongTap: (events, date) {
SnackBar snackBar = SnackBar(content: Text("on LongTap"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
halfHourIndicatorSettings: HourIndicatorSettings(
color: Theme.of(context).dividerColor,
lineStyle: LineStyle.dashed,
Expand Down
4 changes: 4 additions & 0 deletions example/lib/widgets/month_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class MonthViewWidget extends StatelessWidget {
),
);
},
onEventLongTap: (event, date) {
SnackBar snackBar = SnackBar(content: Text("on LongTap"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
);
}
}
4 changes: 4 additions & 0 deletions example/lib/widgets/week_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class WeekViewWidget extends StatelessWidget {
),
);
},
onEventLongTap: (events, date) {
SnackBar snackBar = SnackBar(content: Text("on LongTap"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
);
}
}
5 changes: 5 additions & 0 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
/// Called when user taps on event tile.
final CellTapCallback<T>? onTileTap;

/// Called when user long press on event tile.
final CellTapCallback<T>? onTileLongTap;

final EventScrollConfiguration scrollNotifier;

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

Expand All @@ -361,6 +365,7 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
left: events[index].left,
right: events[index].right,
child: GestureDetector(
onLongPress: () => onTileLongTap?.call(events[index].events, date),
onTap: () => onTileTap?.call(events[index].events, date),
child: Builder(builder: (context) {
if (scrollNotifier.shouldScroll &&
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 @@ -86,6 +86,9 @@ class FilledCell<T extends Object?> extends StatelessWidget {
/// Called when user taps on any event tile.
final TileTapCallback<T>? onTileTap;

/// Called when user long press on any event tile.
final TileTapCallback<T>? onTileLongTap;

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

Expand All @@ -109,6 +112,7 @@ class FilledCell<T extends Object?> extends StatelessWidget {
this.backgroundColor = Colors.blue,
this.highlightColor = Colors.blue,
this.onTileTap,
this.onTileLongTap,
this.tileColor = Colors.blue,
this.highlightRadius = 11,
this.titleColor = Constants.black,
Expand Down Expand Up @@ -156,6 +160,8 @@ class FilledCell<T extends Object?> extends StatelessWidget {
(index) => GestureDetector(
onTap: () =>
onTileTap?.call(events[index], events[index].date),
onLongPress: () => onTileLongTap?.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 @@ -73,6 +73,9 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
/// Called when user taps on event tile.
final CellTapCallback<T>? onTileTap;

/// Called when user long press on event tile.
final CellTapCallback<T>? onTileLongTap;

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

Expand Down Expand Up @@ -136,6 +139,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
required this.eventArranger,
required this.verticalLineOffset,
required this.onTileTap,
required this.onTileLongTap,
required this.onDateLongPress,
required this.onDateTap,
required this.minuteSlotSize,
Expand Down Expand Up @@ -228,6 +232,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
child: EventGenerator<T>(
height: height,
date: date,
onTileLongTap: onTileLongTap,
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 @@ -167,6 +167,9 @@ class DayView<T extends Object?> extends StatefulWidget {
/// This method will be called when user taps on event tile.
final CellTapCallback<T>? onEventTap;

/// This method will be called when user long press on event tile.
final CellTapCallback<T>? onEventLongTap;

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

Expand Down Expand Up @@ -246,6 +249,7 @@ class DayView<T extends Object?> extends StatefulWidget {
this.backgroundColor = Colors.white,
this.scrollOffset,
this.onEventTap,
this.onEventLongTap,
this.onDateLongPress,
this.onDateTap,
this.minuteSlotSize = MinuteSlotSize.minutes60,
Expand Down Expand Up @@ -451,6 +455,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
hourLinePainter: _hourLinePainter,
date: date,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
onDateLongPress: widget.onDateLongPress,
onDateTap: widget.onDateTap,
showLiveLine: widget.showLiveTimeLineInAllDays ||
Expand Down
8 changes: 8 additions & 0 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// This function will only work if [cellBuilder] is null.
final TileTapCallback<T>? onEventTap;

/// This function will be called when user will long press on a single event
/// tile inside a cell.
///
/// This function will only work if [cellBuilder] is null.
final TileTapCallback<T>? onEventLongTap;

/// Builds the name of the weeks.
///
/// Used default week builder if null.
Expand Down Expand Up @@ -173,6 +179,7 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.onPageChange,
this.onCellTap,
this.onEventTap,
this.onEventLongTap,
this.onDateLongPress,
this.startDay = WeekDays.monday,
this.headerStringBuilder,
Expand Down Expand Up @@ -522,6 +529,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
backgroundColor: isInMonth ? Constants.white : Constants.offWhite,
events: events,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
dateStringBuilder: widget.dateStringBuilder,
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
/// Called when user taps on event tile.
final CellTapCallback<T>? onTileTap;

/// Called when user long press on event tile.
final CellTapCallback<T>? onTileLongTap;

/// Defines which days should be displayed in one week.
///
/// By default all the days will be visible.
Expand Down Expand Up @@ -163,6 +166,7 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
required this.weekTitleWidth,
required this.scrollController,
required this.onTileTap,
required this.onTileLongTap,
required this.onDateLongPress,
required this.onDateTap,
required this.weekDays,
Expand Down Expand Up @@ -323,6 +327,7 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
height: height,
date: filteredDates[index],
onTileTap: onTileTap,
onTileLongTap: onTileLongTap,
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 @@ -148,6 +148,9 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// Called when user taps on event tile.
final CellTapCallback<T>? onEventTap;

/// Called when user long press on event tile.
final CellTapCallback<T>? onEventLongTap;

/// Show weekends or not
///
/// Default value is true.
Expand Down Expand Up @@ -253,6 +256,7 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.backgroundColor = Colors.white,
this.scrollOffset = 0.0,
this.onEventTap,
this.onEventLongTap,
this.onDateLongPress,
this.onDateTap,
this.weekDays = WeekDays.values,
Expand Down Expand Up @@ -479,6 +483,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
_liveTimeIndicatorSettings,
timeLineBuilder: _timeLineBuilder,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
onDateLongPress: widget.onDateLongPress,
onDateTap: widget.onDateTap,
eventTileBuilder: _eventTileBuilder,
Expand Down

0 comments on commit fd248d3

Please sign in to comment.