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

Added quarter hour indicator to DayView and both half hour indicator and quarter hour indicator to WeekView. #271

Closed
Closed
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
23 changes: 21 additions & 2 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
final FullDayEventBuilder<T> fullDayEventBuilder;

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

/// Flag to display quarter hours.
final bool showQuarterHours;

/// Settings for half hour indicator lines.
final HourIndicatorSettings halfHourIndicatorSettings;
Expand Down Expand Up @@ -127,7 +130,8 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
required this.fullDayEventBuilder,
required this.scrollController,
required this.dayDetectorBuilder,
required this.showHalfHours,
required this.showHalfHours,
required this.showQuarterHours,
required this.halfHourIndicatorSettings,
}) : super(key: key);

Expand Down Expand Up @@ -178,6 +182,21 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
dashSpaceWidth:
halfHourIndicatorSettings.dashSpaceWidth,
),
),
if (showQuarterHours)
CustomPaint(
size: Size(width, height),
painter: QuarterHourLinePainter(
lineColor: halfHourIndicatorSettings.color,
lineHeight: halfHourIndicatorSettings.height,
offset:
timeLineWidth + halfHourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
lineStyle: halfHourIndicatorSettings.lineStyle,
dashWidth: halfHourIndicatorSettings.dashWidth,
dashSpaceWidth:
halfHourIndicatorSettings.dashSpaceWidth,
),
),
dayDetectorBuilder(
width: width,
Expand Down
8 changes: 7 additions & 1 deletion lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class DayView<T extends Object?> extends StatefulWidget {
/// Defines offset of vertical line from hour line starts.
final double verticalLineOffset;

/// Background colour of day view page.
/// Background color of day view page.
final Color? backgroundColor;

/// Scroll offset of day view page.
Expand Down Expand Up @@ -182,8 +182,12 @@ class DayView<T extends Object?> extends StatefulWidget {
/// Display full day event builder.
final FullDayEventBuilder<T>? fullDayEventBuilder;

/// Show half hour indicator
final bool showHalfHours;

/// Show quarter hour indicator
final bool showQuarterHours;

/// Duration from where default day view will be visible
/// By default it will be Duration(hours:0)
final Duration startDuration;
Expand Down Expand Up @@ -226,6 +230,7 @@ class DayView<T extends Object?> extends StatefulWidget {
this.pageViewPhysics,
this.dayDetectorBuilder,
this.showHalfHours = false,
this.showQuarterHours = false,
this.halfHourIndicatorSettings,
this.startDuration = const Duration(hours: 0),
}) : assert(timeLineOffset >= 0,
Expand Down Expand Up @@ -426,6 +431,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
fullDayEventBuilder: _fullDayEventBuilder,
scrollController: _scrollController,
showHalfHours: widget.showHalfHours,
showQuarterHours: widget.showQuarterHours,
halfHourIndicatorSettings:
_halfHourIndicatorSettings,
),
Expand Down
81 changes: 81 additions & 0 deletions lib/src/painters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,86 @@ class HalfHourLinePainter extends CustomPainter {
}
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return oldDelegate is HourLinePainter &&
(oldDelegate.lineColor != lineColor ||
oldDelegate.offset != offset ||
lineHeight != oldDelegate.lineHeight ||
minuteHeight != oldDelegate.minuteHeight);
}
}

//using HalfHourIndicatorSettings for this too
class QuarterHourLinePainter extends CustomPainter {
/// Color of quarter hour line
final Color lineColor;

/// Height of quarter hour line
final double lineHeight;

/// Offset of quarter hour line from left.
final double offset;

/// Height occupied by one minute of time stamp.
final double minuteHeight;

/// Style of the quarter hour line
final LineStyle lineStyle;

/// Line dash width when using the [LineStyle.dashed] style
final double dashWidth;

/// Line dash space width when using the [LineStyle.dashed] style
final double dashSpaceWidth;

/// Paint quarter hour lines
QuarterHourLinePainter({
required this.lineColor,
required this.lineHeight,
required this.offset,
required this.minuteHeight,
required this.lineStyle,
this.dashWidth = 4,
this.dashSpaceWidth = 4,
});

@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = lineColor
..strokeWidth = lineHeight;

for (var i = 0; i < Constants.hoursADay; i++) {
final dy1 = i * minuteHeight * 60 + (minuteHeight * 15);
final dy2 = i * minuteHeight * 60 + (minuteHeight * 45);

//for the 15 minute line
if (lineStyle == LineStyle.dashed) {
var startX = offset;
while (startX < size.width) {
canvas.drawLine(
Offset(startX, dy1), Offset(startX + dashWidth, dy1), paint);
startX += dashWidth + dashSpaceWidth;
}
} else {
canvas.drawLine(Offset(offset, dy1), Offset(size.width, dy1), paint);
}

// for the 45 minutes line
if (lineStyle == LineStyle.dashed) {
var startX = offset;
while (startX < size.width) {
canvas.drawLine(
Offset(startX, dy2), Offset(startX + dashWidth, dy2), paint);
startX += dashWidth + dashSpaceWidth;
}
} else {
canvas.drawLine(Offset(offset, dy2), Offset(size.width, dy2), paint);
}
}
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return oldDelegate is HourLinePainter &&
Expand All @@ -157,6 +237,7 @@ class HalfHourLinePainter extends CustomPainter {
}
}


/// Paints a single horizontal line at [offset].
class CurrentTimeLinePainter extends CustomPainter {
/// Color of time indicator.
Expand Down
44 changes: 43 additions & 1 deletion lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
/// Settings for hour indicator lines.
final HourIndicatorSettings hourIndicatorSettings;

/// Settings for half hour indicator lines.
final HourIndicatorSettings halfHourIndicatorSettings;

/// Flag to display live line.
final bool showLiveLine;

Expand Down Expand Up @@ -111,6 +114,12 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
/// Display full day events.
final FullDayEventBuilder<T> fullDayEventBuilder;

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

/// Flag to display quarter hours
final bool showQuarterHours;

/// A single page for week view.
const InternalWeekViewPage({
Key? key,
Expand All @@ -123,7 +132,8 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
required this.eventTileBuilder,
required this.controller,
required this.timeLineBuilder,
required this.hourIndicatorSettings,
required this.hourIndicatorSettings,
required this.halfHourIndicatorSettings,
required this.showLiveLine,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute,
Expand All @@ -143,6 +153,8 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
required this.scrollConfiguration,
required this.fullDayEventBuilder,
required this.weekDetectorBuilder,
required this.showHalfHours,
required this.showQuarterHours,
}) : super(key: key);

@override
Expand Down Expand Up @@ -225,6 +237,36 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
showVerticalLine: showVerticalLine,
),
),
if (showHalfHours)
CustomPaint(
size: Size(width, height),
painter: HalfHourLinePainter(
lineColor: halfHourIndicatorSettings.color,
lineHeight: halfHourIndicatorSettings.height,
offset:
timeLineWidth + halfHourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
lineStyle: halfHourIndicatorSettings.lineStyle,
dashWidth: halfHourIndicatorSettings.dashWidth,
dashSpaceWidth:
halfHourIndicatorSettings.dashSpaceWidth,
),
),
if (showQuarterHours)
CustomPaint(
size: Size(width, height),
painter: QuarterHourLinePainter(
lineColor: halfHourIndicatorSettings.color,
lineHeight: halfHourIndicatorSettings.height,
offset:
timeLineWidth + halfHourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
lineStyle: halfHourIndicatorSettings.lineStyle,
dashWidth: halfHourIndicatorSettings.dashWidth,
dashSpaceWidth:
halfHourIndicatorSettings.dashSpaceWidth,
),
),
if (showLiveLine && liveTimeIndicatorSettings.height > 0)
LiveTimeIndicator(
liveTimeIndicatorSettings: liveTimeIndicatorSettings,
Expand Down
27 changes: 25 additions & 2 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class WeekView<T extends Object?> extends StatefulWidget {
/// Settings for hour indicator settings.
final HourIndicatorSettings? hourIndicatorSettings;

/// Settings for half hour and quarter hour indicator settings.
final HourIndicatorSettings? halfHourIndicatorSettings;

/// Settings for live time indicator settings.
final HourIndicatorSettings? liveTimeIndicatorSettings;

Expand Down Expand Up @@ -175,14 +178,20 @@ class WeekView<T extends Object?> extends StatefulWidget {
final MinuteSlotSize minuteSlotSize;

/// Style for WeekView header.
final HeaderStyle headerStyle;
final HeaderStyle headerStyle;

/// Option for SafeArea.
final SafeAreaOption safeAreaOption;

/// Display full day event builder.
final FullDayEventBuilder<T>? fullDayEventBuilder;

///Show half hour indicator
final bool showHalfHours;

///Show quarter hour indicator
final bool showQuarterHours;

/// Main widget for week view.
const WeekView({
Key? key,
Expand All @@ -198,6 +207,7 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.maxDay,
this.initialDay,
this.hourIndicatorSettings,
this.halfHourIndicatorSettings,
this.timeLineBuilder,
this.timeLineWidth,
this.liveTimeIndicatorSettings,
Expand All @@ -224,6 +234,8 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.headerStyle = const HeaderStyle(),
this.safeAreaOption = const SafeAreaOption(),
this.fullDayEventBuilder,
this.showHalfHours = false,
this.showQuarterHours = false,
}) : assert((timeLineOffset) >= 0,
"timeLineOffset must be greater than or equal to 0"),
assert(width == null || width > 0,
Expand Down Expand Up @@ -258,7 +270,8 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {

late EventArranger<T> _eventArranger;

late HourIndicatorSettings _hourIndicatorSettings;
late HourIndicatorSettings _hourIndicatorSettings;
late HourIndicatorSettings _halfHourIndicatorSettings;
late HourIndicatorSettings _liveTimeIndicatorSettings;

late PageController _pageController;
Expand Down Expand Up @@ -418,6 +431,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
eventTileBuilder: _eventTileBuilder,
heightPerMinute: widget.heightPerMinute,
hourIndicatorSettings: _hourIndicatorSettings,
halfHourIndicatorSettings: _halfHourIndicatorSettings,
dates: dates,
showLiveLine: widget.showLiveTimeLineInAllDays ||
_showLiveTimeIndicator(dates),
Expand All @@ -433,6 +447,8 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
minuteSlotSize: widget.minuteSlotSize,
scrollConfiguration: _scrollConfiguration,
fullDayEventBuilder: _fullDayEventBuilder,
showHalfHours: widget.showHalfHours,
showQuarterHours: widget.showQuarterHours,
),
);
},
Expand Down Expand Up @@ -510,6 +526,13 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
_weekTitleWidth =
(_width - _timeLineWidth - _hourIndicatorSettings.offset) /
_totalDaysInWeek;

_halfHourIndicatorSettings = widget.halfHourIndicatorSettings ??
HourIndicatorSettings(
height: widget.heightPerMinute,
color: Constants.defaultBorderColor,
offset: 5,
);
}

void _calculateHeights() {
Expand Down
Loading