Skip to content

Commit

Permalink
Merge pull request #253 from SimformSolutionsPvtLtd/fix/issue_241_hea…
Browse files Browse the repository at this point in the history
…der_callback_changes

fix: 🐛Added a callback for the header title #241.
  • Loading branch information
PRBaraiya authored Nov 3, 2023
2 parents a37536b + 38be203 commit 2ef1d21
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 36 deletions.
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 @@ -198,6 +198,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 @@ -239,7 +242,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 @@ -650,15 +656,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 @@ -33,9 +33,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 @@ -55,7 +55,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 @@ -192,6 +192,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 @@ -235,7 +238,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 @@ -394,7 +400,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 @@ -725,22 +734,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

0 comments on commit 2ef1d21

Please sign in to comment.