Skip to content

Commit

Permalink
fix: 🐛live time indicator position on timeline is not correct when st…
Browse files Browse the repository at this point in the history
…artHour set in day and week view #346 (#349)

- 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
  • Loading branch information
apurva010 authored May 1, 2024
1 parent a3f0c90 commit fadd7f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -85,14 +89,19 @@ class _LiveTimeIndicatorState extends State<LiveTimeIndicator> {
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(
color: widget.liveTimeIndicatorSettings.color,
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,
Expand Down
1 change: 1 addition & 0 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
height: height,
heightPerMinute: heightPerMinute,
timeLineWidth: timeLineWidth,
startHour: startHour,
),
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
height: height,
heightPerMinute: heightPerMinute,
timeLineWidth: timeLineWidth,
startHour: startHour,
),
],
),
Expand Down

0 comments on commit fadd7f5

Please sign in to comment.