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

fix: 🐛Added a callback for the header title #241. #253

Merged
merged 1 commit into from
Nov 3, 2023
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# [1.0.5] (UnReleased)
# [1.0.5] (UnReleased)(https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.5)

- Fixed issue related to auto scroll to initial duration for day
view-[#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269)
- Added
feature added a callback for the default header title
- [#241](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/241)

# [1.0.4 - 9 Aug 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.4)

Expand Down
30 changes: 20 additions & 10 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class DayView<T extends Object?> extends StatefulWidget {
/// By default it will be Duration(hours:0)
final Duration startDuration;

/// Callback for the Header title
final HeaderTitleCallback? onHeaderTitleTap;

/// Main widget for day view.
const DayView({
Key? key,
Expand Down Expand Up @@ -232,7 +235,10 @@ class DayView<T extends Object?> extends StatefulWidget {
this.showHalfHours = false,
this.halfHourIndicatorSettings,
this.startDuration = const Duration(hours: 0),
}) : assert(timeLineOffset >= 0,
this.onHeaderTitleTap,
}) : assert(!(onHeaderTitleTap != null && dayTitleBuilder != null),
"can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"),
assert(timeLineOffset >= 0,
"timeLineOffset must be greater than or equal to 0"),
assert(width == null || width > 0,
"Calendar width must be greater than 0."),
Expand Down Expand Up @@ -639,15 +645,19 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
onNextDay: nextPage,
onPreviousDay: previousPage,
onTitleTapped: () async {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToDate(selectedDate);
if (widget.onHeaderTitleTap != null) {
widget.onHeaderTitleTap!(date);
} else {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToDate(selectedDate);
}
},
headerStyle: widget.headerStyle,
);
Expand Down
28 changes: 19 additions & 9 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// Option for SafeArea.
final SafeAreaOption safeAreaOption;

/// Callback for the Header title
final HeaderTitleCallback? onHeaderTitleTap;

/// Main [Widget] to display month view.
const MonthView({
Key? key,
Expand Down Expand Up @@ -166,7 +169,10 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.weekDayStringBuilder,
this.headerStyle = const HeaderStyle(),
this.safeAreaOption = const SafeAreaOption(),
}) : super(key: key);
this.onHeaderTitleTap,
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
"can't use [onHeaderTitleTap] & [headerBuilder] simultaneously"),
super(key: key);

@override
MonthViewState<T> createState() => MonthViewState<T>();
Expand Down Expand Up @@ -462,15 +468,19 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
Widget _defaultHeaderBuilder(DateTime date) {
return MonthPageHeader(
onTitleTapped: () async {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);
if (widget.onHeaderTitleTap != null) {
widget.onHeaderTitleTap!(date);
} else {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToMonth(selectedDate);
if (selectedDate == null) return;
jumpToMonth(selectedDate);
}
},
onPreviousMonth: previousPage,
date: date,
Expand Down
10 changes: 6 additions & 4 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ typedef WeekDayBuilder = Widget Function(
int day,
);

typedef DateWidgetBuilder = Widget Function(
DateTime date,
);
typedef DateWidgetBuilder = Widget Function(DateTime date);

typedef HeaderTitleCallback = Future<void> Function(DateTime date);

typedef WeekNumberBuilder = Widget? Function(
DateTime firstDayOfWeek,
Expand All @@ -56,7 +56,9 @@ typedef StringProvider = String Function(DateTime date,
{DateTime? secondaryDate});

typedef WeekPageHeaderBuilder = Widget Function(
DateTime startDate, DateTime endDate);
DateTime startDate,
DateTime endDate,
);

typedef TileTapCallback<T extends Object?> = void Function(
CalendarEventData<T> event, DateTime date);
Expand Down
40 changes: 28 additions & 12 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// Display full day event builder.
final FullDayEventBuilder<T>? fullDayEventBuilder;

/// Callback for the Header title
final HeaderTitleCallback? onHeaderTitleTap;

/// Main widget for week view.
const WeekView({
Key? key,
Expand Down Expand Up @@ -224,7 +227,10 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.headerStyle = const HeaderStyle(),
this.safeAreaOption = const SafeAreaOption(),
this.fullDayEventBuilder,
}) : assert((timeLineOffset) >= 0,
this.onHeaderTitleTap,
}) : assert(!(onHeaderTitleTap != null && weekPageHeaderBuilder != null),
"can't use [onHeaderTitleTap] & [weekPageHeaderBuilder] simultaneously"),
assert((timeLineOffset) >= 0,
"timeLineOffset must be greater than or equal to 0"),
assert(width == null || width > 0,
"Calendar width must be greater than 0."),
Expand Down Expand Up @@ -381,7 +387,10 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
_weekHeaderBuilder(_currentStartDate, _currentEndDate),
_weekHeaderBuilder(
_currentStartDate,
_currentEndDate,
),
Expanded(
child: DecoratedBox(
decoration: BoxDecoration(color: widget.backgroundColor),
Expand Down Expand Up @@ -710,22 +719,29 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {

/// Default view header builder. This builder will be used if
/// [widget.dayTitleBuilder] is null.
Widget _defaultWeekPageHeaderBuilder(DateTime startDate, DateTime endDate) {
Widget _defaultWeekPageHeaderBuilder(
DateTime startDate,
DateTime endDate,
) {
return WeekPageHeader(
startDate: _currentStartDate,
endDate: _currentEndDate,
onNextDay: nextPage,
onPreviousDay: previousPage,
onTitleTapped: () async {
final selectedDate = await showDatePicker(
context: context,
initialDate: startDate,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToWeek(selectedDate);
if (widget.onHeaderTitleTap != null) {
widget.onHeaderTitleTap!(startDate);
} else {
final selectedDate = await showDatePicker(
context: context,
initialDate: startDate,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToWeek(selectedDate);
}
},
headerStringBuilder: widget.headerStringBuilder,
headerStyle: widget.headerStyle,
Expand Down
Loading