From fadd7f5bf0f6c57f26c1873d8a7c9590d9d1ee8a Mon Sep 17 00:00:00 2001 From: Apurva-Simform <122270609+apurva010@users.noreply.github.com> Date: Wed, 1 May 2024 10:52:14 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9Blive=20time=20indicator=20po?= =?UTF-8?q?sition=20on=20timeline=20is=20not=20correct=20when=20startHour?= =?UTF-8?q?=20set=20in=20day=20and=20week=20view=20#346=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed/minus startHour minutes from totalMinutes of day to set dy offset of current timeline painter which set live time line indicator properly on timeline --- lib/src/components/_internal_components.dart | 27 ++++++++++++------- lib/src/day_view/_internal_day_view_page.dart | 1 + .../week_view/_internal_week_view_page.dart | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/src/components/_internal_components.dart b/lib/src/components/_internal_components.dart index 79217757..ef1466fe 100644 --- a/lib/src/components/_internal_components.dart +++ b/lib/src/components/_internal_components.dart @@ -35,15 +35,19 @@ class LiveTimeIndicator extends StatefulWidget { /// Defines height occupied by one minute. final double heightPerMinute; + /// First hour displayed in the layout, goes from 0 to 24 + final int startHour; + /// Widget to display tile line according to current time. - const LiveTimeIndicator( - {Key? key, - required this.width, - required this.height, - required this.timeLineWidth, - required this.liveTimeIndicatorSettings, - required this.heightPerMinute}) - : super(key: key); + const LiveTimeIndicator({ + Key? key, + required this.width, + required this.height, + required this.timeLineWidth, + required this.liveTimeIndicatorSettings, + required this.heightPerMinute, + required this.startHour, + }) : super(key: key); @override _LiveTimeIndicatorState createState() => _LiveTimeIndicatorState(); @@ -85,6 +89,10 @@ class _LiveTimeIndicatorState extends State { final timeString = widget.liveTimeIndicatorSettings.timeStringBuilder ?.call(DateTime.now()) ?? '$currentHour:$currentMinute $currentPeriod'; + + /// remove startHour minute from [_currentTime.getTotalMinutes] + /// to set dy offset of live time indicator + final startMinutes = widget.startHour * 60; return CustomPaint( size: Size(widget.width, widget.liveTimeIndicatorSettings.height), painter: CurrentTimeLinePainter( @@ -92,7 +100,8 @@ class _LiveTimeIndicatorState extends State { height: widget.liveTimeIndicatorSettings.height, offset: Offset( widget.timeLineWidth + widget.liveTimeIndicatorSettings.offset, - _currentTime.getTotalMinutes * widget.heightPerMinute, + (_currentTime.getTotalMinutes - startMinutes) * + widget.heightPerMinute, ), timeString: timeString, showBullet: widget.liveTimeIndicatorSettings.showBullet, diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index 07abdb08..02560dce 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -264,6 +264,7 @@ class InternalDayViewPage extends StatelessWidget { height: height, heightPerMinute: heightPerMinute, timeLineWidth: timeLineWidth, + startHour: startHour, ), ), ], diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index cbdac1a1..d3151bf3 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -362,6 +362,7 @@ class InternalWeekViewPage extends StatelessWidget { height: height, heightPerMinute: heightPerMinute, timeLineWidth: timeLineWidth, + startHour: startHour, ), ], ),