Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fixes issue #383: ✨ Add action on tap of timestamp in day & week view #419

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Adds additional configurations for `CalendarPageHeader`, `MonthPageHeader`, `DayPageHeader` and `WeekPageHeader`.
- Added `titleBuilder` to build custom title for header.
- Fixes issue calendar scroll physics for day & week view. [#417](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/417)
- Adds `onTimestampTap` callback in `WeekView`
and `DayView`. [#383](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/383)
- `Deprecations`:
- deprecated `backgroundColor` and `iconColor` from `CalendarPageHeader`, `DayPageHeader`, `MonthPageHeader` and `WeekPageHeader`.
- **Solution:** use `headerStyle` instead.
Expand Down
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 @@ -26,6 +26,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 @@ -21,6 +21,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
27 changes: 19 additions & 8 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class TimeLine extends StatefulWidget {
/// This will display time string in timeline.
final DateWidgetBuilder timeLineBuilder;

/// This method will be called when user taps on timestamp in timeline.
final TimestampCallback? onTimestampTap;

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

Expand Down Expand Up @@ -175,6 +178,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 +291,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 +312,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 @@ -136,6 +136,8 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
/// Use this field to disable the calendar scrolling
final ScrollPhysics? scrollPhysics;

final TimestampCallback? onTimestampTap;

/// Defines a single day page.
const InternalDayViewPage({
Key? key,
Expand Down Expand Up @@ -176,6 +178,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 @@ -330,6 +333,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
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 @@ -158,6 +158,9 @@ class DayView<T extends Object?> extends StatefulWidget {
/// initial offset.
final double? scrollOffset;

/// This method will be called when user taps on timestamp in timeline.
final TimestampCallback? onTimestampTap;

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

Expand Down Expand Up @@ -273,6 +276,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 +471,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
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 @@ -163,6 +163,9 @@ class InternalWeekViewPage<T extends Object?> extends StatefulWidget {
/// Use this field to disable the calendar scrolling
final ScrollPhysics? scrollPhysics;

/// This method will be called when user taps on timestamp in timeline.
final TimestampCallback? onTimestampTap;

/// A single page for week view.
const InternalWeekViewPage({
Key? key,
Expand Down Expand Up @@ -205,6 +208,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.scrollPhysics,
Expand Down Expand Up @@ -475,6 +479,7 @@ class _InternalWeekViewPageState<T extends Object?>
liveTimeIndicatorSettings:
widget.liveTimeIndicatorSettings,
endHour: widget.endHour,
onTimestampTap: widget.onTimestampTap,
),
if (widget.showLiveLine &&
widget.liveTimeIndicatorSettings.height > 0)
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 @@ -149,6 +149,9 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// Scroll offset of week view page.
final double scrollOffset;

/// This method will be called when user taps on timestamp in timeline.
final TimestampCallback? onTimestampTap;

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

Expand Down Expand Up @@ -306,6 +309,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 @@ -527,6 +531,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
Loading