From 776409e09d2f79a225fa6eb1f6d4e4fce59c12f2 Mon Sep 17 00:00:00 2001 From: prabinlamsal19 Date: Fri, 29 Sep 2023 16:28:38 +0545 Subject: [PATCH 1/4] feat: added day_view parameters --- lib/src/day_view/day_view.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 73ef9bee..f53158ba 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -142,7 +142,7 @@ class DayView 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. @@ -182,8 +182,12 @@ class DayView extends StatefulWidget { /// Display full day event builder. final FullDayEventBuilder? fullDayEventBuilder; + /// Show half hour lines final bool showHalfHours; + /// Show quarter hour lines + final bool showQuarterHours; + /// Duration from where default day view will be visible /// By default it will be Duration(hours:0) final Duration startDuration; @@ -226,6 +230,7 @@ class DayView extends StatefulWidget { this.pageViewPhysics, this.dayDetectorBuilder, this.showHalfHours = false, + this.showQuarterHours = false, this.halfHourIndicatorSettings, this.startDuration = const Duration(hours: 0), }) : assert(timeLineOffset >= 0, @@ -426,6 +431,7 @@ class DayViewState extends State> { fullDayEventBuilder: _fullDayEventBuilder, scrollController: _scrollController, showHalfHours: widget.showHalfHours, + showQuarterHours: widget.showQuarterHours, halfHourIndicatorSettings: _halfHourIndicatorSettings, ), From 1c29475cc808116132b6424a961822465f05c946 Mon Sep 17 00:00:00 2001 From: prabinlamsal19 Date: Fri, 29 Sep 2023 16:31:45 +0545 Subject: [PATCH 2/4] feat: quarter hour painter --- lib/src/day_view/_internal_day_view_page.dart | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index 706cf02c..6e9dd926 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -93,7 +93,10 @@ class InternalDayViewPage extends StatelessWidget { final FullDayEventBuilder 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; @@ -127,7 +130,8 @@ class InternalDayViewPage 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); @@ -178,6 +182,21 @@ class InternalDayViewPage 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, From ff3c085ca0a109697840c6542b2773d304e2d2c2 Mon Sep 17 00:00:00 2001 From: prabinlamsal19 Date: Fri, 29 Sep 2023 16:37:03 +0545 Subject: [PATCH 3/4] feat: implemented dayview quarter hour line --- lib/src/painters.dart | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 1c2a539b..1b91c6a5 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -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 && @@ -157,6 +237,7 @@ class HalfHourLinePainter extends CustomPainter { } } + /// Paints a single horizontal line at [offset]. class CurrentTimeLinePainter extends CustomPainter { /// Color of time indicator. From 9e3a23d562d6624d9efee80e2d3c95e1ede8bb45 Mon Sep 17 00:00:00 2001 From: prabinlamsal19 Date: Fri, 29 Sep 2023 17:28:46 +0545 Subject: [PATCH 4/4] feat: halfHourIndicator and quarterHourIndicator on WeekView added --- lib/src/day_view/day_view.dart | 4 +- .../week_view/_internal_week_view_page.dart | 44 ++++++++++++++++++- lib/src/week_view/week_view.dart | 27 +++++++++++- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index f53158ba..0144cdc3 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -182,10 +182,10 @@ class DayView extends StatefulWidget { /// Display full day event builder. final FullDayEventBuilder? fullDayEventBuilder; - /// Show half hour lines + /// Show half hour indicator final bool showHalfHours; - /// Show quarter hour lines + /// Show quarter hour indicator final bool showQuarterHours; /// Duration from where default day view will be visible diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index 3f7ec3b4..18ac1b32 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -37,6 +37,9 @@ class InternalWeekViewPage 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; @@ -111,6 +114,12 @@ class InternalWeekViewPage extends StatelessWidget { /// Display full day events. final FullDayEventBuilder 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, @@ -123,7 +132,8 @@ class InternalWeekViewPage 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, @@ -143,6 +153,8 @@ class InternalWeekViewPage extends StatelessWidget { required this.scrollConfiguration, required this.fullDayEventBuilder, required this.weekDetectorBuilder, + required this.showHalfHours, + required this.showQuarterHours, }) : super(key: key); @override @@ -225,6 +237,36 @@ class InternalWeekViewPage 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, diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index 8357e98c..e40d34fa 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -85,6 +85,9 @@ class WeekView 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; @@ -175,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; @@ -183,6 +186,12 @@ class WeekView extends StatefulWidget { /// Display full day event builder. final FullDayEventBuilder? fullDayEventBuilder; + ///Show half hour indicator + final bool showHalfHours; + + ///Show quarter hour indicator + final bool showQuarterHours; + /// Main widget for week view. const WeekView({ Key? key, @@ -198,6 +207,7 @@ class WeekView extends StatefulWidget { this.maxDay, this.initialDay, this.hourIndicatorSettings, + this.halfHourIndicatorSettings, this.timeLineBuilder, this.timeLineWidth, this.liveTimeIndicatorSettings, @@ -224,6 +234,8 @@ class WeekView 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, @@ -258,7 +270,8 @@ class WeekViewState extends State> { late EventArranger _eventArranger; - late HourIndicatorSettings _hourIndicatorSettings; + late HourIndicatorSettings _hourIndicatorSettings; + late HourIndicatorSettings _halfHourIndicatorSettings; late HourIndicatorSettings _liveTimeIndicatorSettings; late PageController _pageController; @@ -418,6 +431,7 @@ class WeekViewState extends State> { eventTileBuilder: _eventTileBuilder, heightPerMinute: widget.heightPerMinute, hourIndicatorSettings: _hourIndicatorSettings, + halfHourIndicatorSettings: _halfHourIndicatorSettings, dates: dates, showLiveLine: widget.showLiveTimeLineInAllDays || _showLiveTimeIndicator(dates), @@ -433,6 +447,8 @@ class WeekViewState extends State> { minuteSlotSize: widget.minuteSlotSize, scrollConfiguration: _scrollConfiguration, fullDayEventBuilder: _fullDayEventBuilder, + showHalfHours: widget.showHalfHours, + showQuarterHours: widget.showQuarterHours, ), ); }, @@ -510,6 +526,13 @@ class WeekViewState extends State> { _weekTitleWidth = (_width - _timeLineWidth - _hourIndicatorSettings.offset) / _totalDaysInWeek; + + _halfHourIndicatorSettings = widget.halfHourIndicatorSettings ?? + HourIndicatorSettings( + height: widget.heightPerMinute, + color: Constants.defaultBorderColor, + offset: 5, + ); } void _calculateHeights() {