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/all day header title #361

Merged
merged 3 commits into from
May 9, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- # [1.1.1] (UnReleased)
- Added showWeekTileBorder field whether to show border for header in month view. [#306](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/306)
- Fixed an issue related to hiding day, which is not in the current month in MonthView. [#328](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/328)
- Added header title for full day events in week view. [#308](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/308)
- Added support for double tapping gestures on any event in day, week, and month view. [#195](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/195)
- Added support to set end time of day and week view. [#298](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/298)
- Added support for horizontal scroll physics of week and month view page. [#314](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/314)
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ WeekView(
hourLinePainter: (lineColor, lineHeight, offset, minuteHeight, showVerticalLine, verticalLineOffset) {
return //Your custom painter.
},
weekPageHeaderBuilder: WeekHeader.hidden // To hide week header
weekPageHeaderBuilder: WeekHeader.hidden, // To hide week header
fullDayHeaderTitle: 'All day', // To set full day events header title
fullDayHeaderTextConfig: FullDayHeaderTextConfig(
textAlign: TextAlign.center,
textOverflow: TextOverflow.ellipsis,
maxLines: 2,
), // To set full day events header text config
);
```

Expand Down
13 changes: 13 additions & 0 deletions lib/src/components/week_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ class WeekPageHeader extends CalendarPageHeader {
"${secondaryDate != null ? "${secondaryDate.day} / "
"${secondaryDate.month} / ${secondaryDate.year}" : ""}";
}

class FullDayHeaderTextConfig {
/// Set full day events header text config
const FullDayHeaderTextConfig({
this.textAlign = TextAlign.center,
this.maxLines = 2,
this.textOverflow = TextOverflow.ellipsis,
});

final TextAlign textAlign;
final int maxLines;
final TextOverflow textOverflow;
}
70 changes: 52 additions & 18 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/material.dart';

import '../components/_internal_components.dart';
import '../components/week_view_components.dart';
import '../components/event_scroll_notifier.dart';
import '../enumerations.dart';
import '../event_arrangers/event_arrangers.dart';
Expand Down Expand Up @@ -144,6 +145,12 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
/// This field will be used to set end hour for week view
final int endHour;

/// Title of the full day events row
final String fullDayHeaderTitle;

/// Defines full day events header text config
final FullDayHeaderTextConfig fullDayHeaderTextConfig;

/// A single page for week view.
const InternalWeekViewPage({
Key? key,
Expand Down Expand Up @@ -187,6 +194,8 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
required this.endHour,
this.fullDayHeaderTitle = '',
required this.fullDayHeaderTextConfig,
}) : super(key: key);

@override
Expand Down Expand Up @@ -229,25 +238,50 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
),
SizedBox(
width: width,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(width: timeLineWidth + hourIndicatorSettings.offset),
...List.generate(
filteredDates.length,
(index) {
final fullDayEventList =
controller.getFullDayEvent(filteredDates[index]);
return SizedBox(
width: weekTitleWidth,
child: fullDayEventBuilder.call(
fullDayEventList,
dates[index],
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: hourIndicatorSettings.color,
width: 2,
),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (fullDayHeaderTitle.isNotEmpty)
Container(
width: timeLineWidth + hourIndicatorSettings.offset,
padding: const EdgeInsets.symmetric(
vertical: 2,
horizontal: 1,
),
);
},
)
],
child: Text(
fullDayHeaderTitle,
textAlign: fullDayHeaderTextConfig.textAlign,
maxLines: fullDayHeaderTextConfig.maxLines,
overflow: fullDayHeaderTextConfig.textOverflow,
),
),
...List.generate(
filteredDates.length,
(index) {
final fullDayEventList =
controller.getFullDayEvent(filteredDates[index]);
return Container(
width: weekTitleWidth,
child: fullDayEventList.isEmpty
? null
: fullDayEventBuilder.call(
fullDayEventList,
dates[index],
),
);
},
)
],
),
),
),
Expanded(
Expand Down
15 changes: 15 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// This can be used to disable the horizontal scroll of a page.
final ScrollPhysics? pageViewPhysics;

/// Title of the full day events row
final String fullDayHeaderTitle;

/// Defines full day events header text config
final FullDayHeaderTextConfig? fullDayHeaderTextConfig;

/// Main widget for week view.
const WeekView({
Key? key,
Expand Down Expand Up @@ -286,6 +292,8 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.pageViewPhysics,
this.onEventDoubleTap,
this.endHour = Constants.hoursADay,
this.fullDayHeaderTitle = '',
this.fullDayHeaderTextConfig,
}) : assert(!(onHeaderTitleTap != null && weekPageHeaderBuilder != null),
"can't use [onHeaderTitleTap] & [weekPageHeaderBuilder] simultaneously"),
assert((timeLineOffset) >= 0,
Expand Down Expand Up @@ -327,6 +335,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
late DateTime _currentWeek;
late int _totalWeeks;
late int _currentIndex;
late String _fullDayHeaderTitle;

late EventArranger<T> _eventArranger;

Expand All @@ -346,6 +355,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
late WeekNumberBuilder _weekNumberBuilder;
late FullDayEventBuilder<T> _fullDayEventBuilder;
late DetectorBuilder _weekDetectorBuilder;
late FullDayHeaderTextConfig _fullDayHeaderTextConfig;

late double _weekTitleWidth;
late int _totalDaysInWeek;
Expand Down Expand Up @@ -388,6 +398,9 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
_eventArranger = widget.eventArranger ?? SideEventArranger<T>();

_assignBuilders();
_fullDayHeaderTitle = widget.fullDayHeaderTitle;
_fullDayHeaderTextConfig =
widget.fullDayHeaderTextConfig ?? FullDayHeaderTextConfig();
}

@override
Expand Down Expand Up @@ -533,6 +546,8 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
widget.emulateVerticalOffsetBy,
showWeekDayAtBottom: widget.showWeekDayAtBottom,
endHour: _endHour,
fullDayHeaderTitle: _fullDayHeaderTitle,
fullDayHeaderTextConfig: _fullDayHeaderTextConfig,
),
);
},
Expand Down
Loading