Skip to content

Commit

Permalink
feat: added emulateVerticalOffsetBy parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
prabinlamsal19 committed Oct 2, 2023
1 parent 9e3a23d commit 10e7d1f
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 105 deletions.
9 changes: 6 additions & 3 deletions lib/src/painters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class HourLinePainter extends CustomPainter {
/// Line dash space width when using the [LineStyle.dashed] style
final double dashSpaceWidth;

/// Emulates offset of vertical line from hour line starts.
final double emulateVerticalOffsetBy;

/// Paints 24 hour lines.
HourLinePainter({
required this.lineColor,
Expand All @@ -47,6 +50,7 @@ class HourLinePainter extends CustomPainter {
this.lineStyle = LineStyle.solid,
this.dashWidth = 4,
this.dashSpaceWidth = 4,
this.emulateVerticalOffsetBy = 0,
});

@override
Expand All @@ -58,7 +62,7 @@ class HourLinePainter extends CustomPainter {
for (var i = 1; i < Constants.hoursADay; i++) {
final dy = i * minuteHeight * 60;
if (lineStyle == LineStyle.dashed) {
var startX = offset;
var startX = offset + emulateVerticalOffsetBy;
while (startX < size.width) {
canvas.drawLine(
Offset(startX, dy), Offset(startX + dashWidth, dy), paint);
Expand Down Expand Up @@ -155,7 +159,7 @@ class HalfHourLinePainter extends CustomPainter {
lineHeight != oldDelegate.lineHeight ||
minuteHeight != oldDelegate.minuteHeight);
}
}
}

//using HalfHourIndicatorSettings for this too
class QuarterHourLinePainter extends CustomPainter {
Expand Down Expand Up @@ -237,7 +241,6 @@ class QuarterHourLinePainter extends CustomPainter {
}
}


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

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

/// Flag to display live line.
Expand Down Expand Up @@ -115,47 +115,51 @@ class InternalWeekViewPage<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;
/// Flag to display quarter hours
final bool showQuarterHours;

/// Emulate vertical line offset from hour line starts.
final double emulateVerticalOffsetBy;

/// A single page for week view.
const InternalWeekViewPage({
Key? key,
required this.showVerticalLine,
required this.weekTitleHeight,
required this.weekDayBuilder,
required this.weekNumberBuilder,
required this.width,
required this.dates,
required this.eventTileBuilder,
required this.controller,
required this.timeLineBuilder,
required this.hourIndicatorSettings,
required this.halfHourIndicatorSettings,
required this.showLiveLine,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute,
required this.timeLineWidth,
required this.timeLineOffset,
required this.height,
required this.hourHeight,
required this.eventArranger,
required this.verticalLineOffset,
required this.weekTitleWidth,
required this.scrollController,
required this.onTileTap,
required this.onDateLongPress,
required this.onDateTap,
required this.weekDays,
required this.minuteSlotSize,
required this.scrollConfiguration,
required this.fullDayEventBuilder,
required this.weekDetectorBuilder,
required this.showHalfHours,
required this.showQuarterHours,
}) : super(key: key);
const InternalWeekViewPage(
{Key? key,
required this.showVerticalLine,
required this.weekTitleHeight,
required this.weekDayBuilder,
required this.weekNumberBuilder,
required this.width,
required this.dates,
required this.eventTileBuilder,
required this.controller,
required this.timeLineBuilder,
required this.hourIndicatorSettings,
required this.halfHourIndicatorSettings,
required this.showLiveLine,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute,
required this.timeLineWidth,
required this.timeLineOffset,
required this.height,
required this.hourHeight,
required this.eventArranger,
required this.verticalLineOffset,
required this.weekTitleWidth,
required this.scrollController,
required this.onTileTap,
required this.onDateLongPress,
required this.onDateTap,
required this.weekDays,
required this.minuteSlotSize,
required this.scrollConfiguration,
required this.fullDayEventBuilder,
required this.weekDetectorBuilder,
required this.showHalfHours,
required this.showQuarterHours,
required this.emulateVerticalOffsetBy})
: super(key: key);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -229,15 +233,15 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
CustomPaint(
size: Size(width, height),
painter: HourLinePainter(
lineColor: hourIndicatorSettings.color,
lineHeight: hourIndicatorSettings.height,
offset: timeLineWidth + hourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
verticalLineOffset: verticalLineOffset,
showVerticalLine: showVerticalLine,
),
lineColor: hourIndicatorSettings.color,
lineHeight: hourIndicatorSettings.height,
offset: timeLineWidth + hourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
verticalLineOffset: verticalLineOffset,
showVerticalLine: showVerticalLine,
emulateVerticalOffsetBy: emulateVerticalOffsetBy),
),
if (showHalfHours)
if (showHalfHours)
CustomPaint(
size: Size(width, height),
painter: HalfHourLinePainter(
Expand All @@ -251,8 +255,8 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
dashSpaceWidth:
halfHourIndicatorSettings.dashSpaceWidth,
),
),
if (showQuarterHours)
),
if (showQuarterHours)
CustomPaint(
size: Size(width, height),
painter: QuarterHourLinePainter(
Expand Down
113 changes: 60 additions & 53 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,65 +178,69 @@ 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 half hour indicator
final bool showHalfHours;

///Show quarter hour indicator
///Show quarter hour indicator
final bool showQuarterHours;

///Emulates offset of vertical line from hour line starts.
final double emulateVerticalOffsetBy;

/// Main widget for week view.
const WeekView({
Key? key,
this.controller,
this.eventTileBuilder,
this.pageTransitionDuration = const Duration(milliseconds: 300),
this.pageTransitionCurve = Curves.ease,
this.heightPerMinute = 1,
this.timeLineOffset = 0,
this.showLiveTimeLineInAllDays = false,
this.width,
this.minDay,
this.maxDay,
this.initialDay,
this.hourIndicatorSettings,
this.halfHourIndicatorSettings,
this.timeLineBuilder,
this.timeLineWidth,
this.liveTimeIndicatorSettings,
this.onPageChange,
this.weekPageHeaderBuilder,
this.eventArranger,
this.weekTitleHeight = 50,
this.weekDayBuilder,
this.weekNumberBuilder,
this.backgroundColor = Colors.white,
this.scrollOffset = 0.0,
this.onEventTap,
this.onDateLongPress,
this.onDateTap,
this.weekDays = WeekDays.values,
this.showWeekends = true,
this.startDay = WeekDays.monday,
this.minuteSlotSize = MinuteSlotSize.minutes60,
this.weekDetectorBuilder,
this.headerStringBuilder,
this.timeLineStringBuilder,
this.weekDayStringBuilder,
this.weekDayDateStringBuilder,
this.headerStyle = const HeaderStyle(),
this.safeAreaOption = const SafeAreaOption(),
this.fullDayEventBuilder,
this.showHalfHours = false,
this.showQuarterHours = false,
}) : assert((timeLineOffset) >= 0,
const WeekView(
{Key? key,
this.controller,
this.eventTileBuilder,
this.pageTransitionDuration = const Duration(milliseconds: 300),
this.pageTransitionCurve = Curves.ease,
this.heightPerMinute = 1,
this.timeLineOffset = 0,
this.showLiveTimeLineInAllDays = false,
this.width,
this.minDay,
this.maxDay,
this.initialDay,
this.hourIndicatorSettings,
this.halfHourIndicatorSettings,
this.timeLineBuilder,
this.timeLineWidth,
this.liveTimeIndicatorSettings,
this.onPageChange,
this.weekPageHeaderBuilder,
this.eventArranger,
this.weekTitleHeight = 50,
this.weekDayBuilder,
this.weekNumberBuilder,
this.backgroundColor = Colors.white,
this.scrollOffset = 0.0,
this.onEventTap,
this.onDateLongPress,
this.onDateTap,
this.weekDays = WeekDays.values,
this.showWeekends = true,
this.startDay = WeekDays.monday,
this.minuteSlotSize = MinuteSlotSize.minutes60,
this.weekDetectorBuilder,
this.headerStringBuilder,
this.timeLineStringBuilder,
this.weekDayStringBuilder,
this.weekDayDateStringBuilder,
this.headerStyle = const HeaderStyle(),
this.safeAreaOption = const SafeAreaOption(),
this.fullDayEventBuilder,
this.showHalfHours = false,
this.showQuarterHours = false,
this.emulateVerticalOffsetBy = 10.0})
: 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 @@ -270,7 +274,7 @@ 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;

Expand Down Expand Up @@ -431,7 +435,8 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
eventTileBuilder: _eventTileBuilder,
heightPerMinute: widget.heightPerMinute,
hourIndicatorSettings: _hourIndicatorSettings,
halfHourIndicatorSettings: _halfHourIndicatorSettings,
halfHourIndicatorSettings:
_halfHourIndicatorSettings,
dates: dates,
showLiveLine: widget.showLiveTimeLineInAllDays ||
_showLiveTimeIndicator(dates),
Expand All @@ -447,8 +452,10 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
minuteSlotSize: widget.minuteSlotSize,
scrollConfiguration: _scrollConfiguration,
fullDayEventBuilder: _fullDayEventBuilder,
showHalfHours: widget.showHalfHours,
showHalfHours: widget.showHalfHours,
showQuarterHours: widget.showQuarterHours,
emulateVerticalOffsetBy:
widget.emulateVerticalOffsetBy,
),
);
},
Expand Down Expand Up @@ -527,8 +534,8 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
(_width - _timeLineWidth - _hourIndicatorSettings.offset) /
_totalDaysInWeek;

_halfHourIndicatorSettings = widget.halfHourIndicatorSettings ??
HourIndicatorSettings(
_halfHourIndicatorSettings = widget.halfHourIndicatorSettings ??
HourIndicatorSettings(
height: widget.heightPerMinute,
color: Constants.defaultBorderColor,
offset: 5,
Expand Down

0 comments on commit 10e7d1f

Please sign in to comment.