From 10e7d1fd617dc1977f537e407c6c79ec743a5980 Mon Sep 17 00:00:00 2001 From: prabinlamsal19 Date: Mon, 2 Oct 2023 12:10:13 +0545 Subject: [PATCH] feat: added emulateVerticalOffsetBy parameter --- lib/src/painters.dart | 9 +- .../week_view/_internal_week_view_page.dart | 102 ++++++++-------- lib/src/week_view/week_view.dart | 113 ++++++++++-------- 3 files changed, 119 insertions(+), 105 deletions(-) diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 1b91c6a5..52a0d250 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -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, @@ -47,6 +50,7 @@ class HourLinePainter extends CustomPainter { this.lineStyle = LineStyle.solid, this.dashWidth = 4, this.dashSpaceWidth = 4, + this.emulateVerticalOffsetBy = 0, }); @override @@ -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); @@ -155,7 +159,7 @@ class HalfHourLinePainter extends CustomPainter { lineHeight != oldDelegate.lineHeight || minuteHeight != oldDelegate.minuteHeight); } -} +} //using HalfHourIndicatorSettings for this too class QuarterHourLinePainter extends CustomPainter { @@ -237,7 +241,6 @@ class QuarterHourLinePainter extends CustomPainter { } } - /// Paints a single horizontal line at [offset]. class CurrentTimeLinePainter extends CustomPainter { /// Color of time indicator. diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index 18ac1b32..85c846c8 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -37,7 +37,7 @@ class InternalWeekViewPage 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. @@ -115,47 +115,51 @@ class InternalWeekViewPage extends StatelessWidget { final FullDayEventBuilder 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) { @@ -229,15 +233,15 @@ class InternalWeekViewPage 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( @@ -251,8 +255,8 @@ class InternalWeekViewPage extends StatelessWidget { dashSpaceWidth: halfHourIndicatorSettings.dashSpaceWidth, ), - ), - if (showQuarterHours) + ), + if (showQuarterHours) CustomPaint( size: Size(width, height), painter: QuarterHourLinePainter( diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index e40d34fa..9564ddeb 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -178,7 +178,7 @@ class WeekView extends StatefulWidget { final MinuteSlotSize minuteSlotSize; /// Style for WeekView header. - final HeaderStyle headerStyle; + final HeaderStyle headerStyle; /// Option for SafeArea. final SafeAreaOption safeAreaOption; @@ -186,57 +186,61 @@ class WeekView extends StatefulWidget { /// Display full day event builder. final FullDayEventBuilder? 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."), @@ -270,7 +274,7 @@ class WeekViewState extends State> { late EventArranger _eventArranger; - late HourIndicatorSettings _hourIndicatorSettings; + late HourIndicatorSettings _hourIndicatorSettings; late HourIndicatorSettings _halfHourIndicatorSettings; late HourIndicatorSettings _liveTimeIndicatorSettings; @@ -431,7 +435,8 @@ class WeekViewState extends State> { eventTileBuilder: _eventTileBuilder, heightPerMinute: widget.heightPerMinute, hourIndicatorSettings: _hourIndicatorSettings, - halfHourIndicatorSettings: _halfHourIndicatorSettings, + halfHourIndicatorSettings: + _halfHourIndicatorSettings, dates: dates, showLiveLine: widget.showLiveTimeLineInAllDays || _showLiveTimeIndicator(dates), @@ -447,8 +452,10 @@ class WeekViewState extends State> { minuteSlotSize: widget.minuteSlotSize, scrollConfiguration: _scrollConfiguration, fullDayEventBuilder: _fullDayEventBuilder, - showHalfHours: widget.showHalfHours, + showHalfHours: widget.showHalfHours, showQuarterHours: widget.showQuarterHours, + emulateVerticalOffsetBy: + widget.emulateVerticalOffsetBy, ), ); }, @@ -527,8 +534,8 @@ class WeekViewState extends State> { (_width - _timeLineWidth - _hourIndicatorSettings.offset) / _totalDaysInWeek; - _halfHourIndicatorSettings = widget.halfHourIndicatorSettings ?? - HourIndicatorSettings( + _halfHourIndicatorSettings = widget.halfHourIndicatorSettings ?? + HourIndicatorSettings( height: widget.heightPerMinute, color: Constants.defaultBorderColor, offset: 5,