Skip to content

Commit

Permalink
feat: Fixes issue #383: ✨ Add action on tap of timestamp in day & wee…
Browse files Browse the repository at this point in the history
…k view
  • Loading branch information
shubham-jitiya-simform committed Nov 5, 2024
1 parent 982747f commit 658284e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
6 changes: 6 additions & 0 deletions example/lib/widgets/day_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class DayViewWidget extends StatelessWidget {
hourIndicatorSettings: HourIndicatorSettings(
color: Theme.of(context).dividerColor,
),
onTimestampTap: (date) {
SnackBar snackBar = SnackBar(
content: Text("On tap: ${date.hour} Hr : ${date.minute} Min"),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
onEventTap: (events, date) {
Navigator.of(context).push(
MaterialPageRoute(
Expand Down
6 changes: 6 additions & 0 deletions example/lib/widgets/week_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class WeekViewWidget extends StatelessWidget {
color: Colors.redAccent,
showTime: true,
),
onTimestampTap: (date) {
SnackBar snackBar = SnackBar(
content: Text("On tap: ${date.hour} Hr : ${date.minute} Min"),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
onEventTap: (events, date) {
Navigator.of(context).push(
MaterialPageRoute(
Expand Down
26 changes: 18 additions & 8 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class TimeLine extends StatefulWidget {
/// This will display time string in timeline.
final DateWidgetBuilder timeLineBuilder;

final TimestampCallback? onTimestampTap;

/// Flag to display half hours.
final bool showHalfHours;

Expand Down Expand Up @@ -175,6 +177,7 @@ class TimeLine extends StatefulWidget {
required this.height,
required this.timeLineOffset,
required this.timeLineBuilder,
required this.onTimestampTap,
this.startHour = 0,
this.showHalfHours = false,
this.showQuarterHours = false,
Expand Down Expand Up @@ -287,6 +290,14 @@ class _TimeLineState extends State<TimeLine> {
required int hour,
int minutes = 0,
}) {
final dateTime = DateTime(
TimeLine._date.year,
TimeLine._date.month,
TimeLine._date.day,
hour,
minutes,
);

return Visibility(
visible: !((_currentTime.minute >= 45 && _currentTime.hour == hour - 1) ||
(_currentTime.minute <= 15 && _currentTime.hour == hour)) ||
Expand All @@ -300,14 +311,13 @@ class _TimeLineState extends State<TimeLine> {
child: Container(
height: widget.hourHeight,
width: widget.timeLineWidth,
child: widget.timeLineBuilder.call(
DateTime(
TimeLine._date.year,
TimeLine._date.month,
TimeLine._date.day,
hour,
minutes,
),
child: InkWell(
onTap: () {
if (widget.onTimestampTap != null) {
widget.onTimestampTap!(dateTime);
}
},
child: widget.timeLineBuilder.call(dateTime),
),
),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
/// Flag to keep scrollOffset of pages on page change
final bool keepScrollOffset;

final TimestampCallback? onTimestampTap;

/// Defines a single day page.
const InternalDayViewPage({
Key? key,
Expand Down Expand Up @@ -172,6 +174,7 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
required this.quarterHourIndicatorSettings,
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
required this.onTimestampTap,
this.keepScrollOffset = false,
}) : super(key: key);

Expand Down Expand Up @@ -325,6 +328,7 @@ class _InternalDayViewPageState<T extends Object?>
key: ValueKey(widget.heightPerMinute),
liveTimeIndicatorSettings:
widget.liveTimeIndicatorSettings,
onTimestampTap: widget.onTimestampTap,
),
if (widget.showLiveLine &&
widget.liveTimeIndicatorSettings.height > 0)
Expand Down
4 changes: 4 additions & 0 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class DayView<T extends Object?> extends StatefulWidget {
/// initial offset.
final double? scrollOffset;

final TimestampCallback? onTimestampTap;

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

Expand Down Expand Up @@ -273,6 +275,7 @@ class DayView<T extends Object?> extends StatefulWidget {
this.onEventDoubleTap,
this.endHour = Constants.hoursADay,
this.keepScrollOffset = false,
this.onTimestampTap,
}) : assert(!(onHeaderTitleTap != null && dayTitleBuilder != null),
"can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"),
assert(timeLineOffset >= 0,
Expand Down Expand Up @@ -467,6 +470,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
hourIndicatorSettings: _hourIndicatorSettings,
hourLinePainter: _hourLinePainter,
date: date,
onTimestampTap: widget.onTimestampTap,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
onDateLongPress: widget.onDateLongPress,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef DatePressCallback = void Function(DateTime date);

typedef DateTapCallback = void Function(DateTime date);

typedef TimestampCallback = void Function(DateTime date);

typedef EventFilter<T extends Object?> = List<CalendarEventData<T>> Function(
DateTime date, List<CalendarEventData<T>> events);

Expand Down
4 changes: 4 additions & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class InternalWeekViewPage<T extends Object?> extends StatefulWidget {
/// Flag to keep scrollOffset of pages on page change
final bool keepScrollOffset;

final TimestampCallback? onTimestampTap;

/// A single page for week view.
const InternalWeekViewPage({
Key? key,
Expand Down Expand Up @@ -202,6 +204,7 @@ class InternalWeekViewPage<T extends Object?> extends StatefulWidget {
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
required this.endHour,
required this.onTimestampTap,
this.fullDayHeaderTitle = '',
required this.fullDayHeaderTextConfig,
required this.scrollListener,
Expand Down Expand Up @@ -470,6 +473,7 @@ class _InternalWeekViewPageState<T extends Object?>
liveTimeIndicatorSettings:
widget.liveTimeIndicatorSettings,
endHour: widget.endHour,
onTimestampTap: widget.onTimestampTap,
),
if (widget.showLiveLine &&
widget.liveTimeIndicatorSettings.height > 0)
Expand Down
4 changes: 4 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// Scroll offset of week view page.
final double scrollOffset;

final TimestampCallback? onTimestampTap;

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

Expand Down Expand Up @@ -302,6 +304,7 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.fullDayHeaderTitle = '',
this.fullDayHeaderTextConfig,
this.keepScrollOffset = false,
this.onTimestampTap,
}) : assert(!(onHeaderTitleTap != null && weekPageHeaderBuilder != null),
"can't use [onHeaderTitleTap] & [weekPageHeaderBuilder] simultaneously"),
assert((timeLineOffset) >= 0,
Expand Down Expand Up @@ -523,6 +526,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
liveTimeIndicatorSettings:
_liveTimeIndicatorSettings,
timeLineBuilder: _timeLineBuilder,
onTimestampTap: widget.onTimestampTap,
onTileTap: widget.onEventTap,
onTileLongTap: widget.onEventLongTap,
onDateLongPress: widget.onDateLongPress,
Expand Down

0 comments on commit 658284e

Please sign in to comment.