Skip to content

Commit

Permalink
Solved Intermittent Gap in Timeline Display Causing Missing Hour Simf…
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankheliverse committed Jun 19, 2024
1 parent 76c5430 commit ca92736
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 101 deletions.
79 changes: 44 additions & 35 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _LiveTimeIndicatorState extends State<LiveTimeIndicator> {
final currentMinute = _currentTime.minute.appendLeadingZero();
final currentPeriod = _currentTime.period.name;
final timeString = widget.liveTimeIndicatorSettings.timeStringBuilder
?.call(DateTime.now()) ??
?.call(DateTime.now()) ??
'$currentHour:$currentMinute $currentPeriod';

/// remove startHour minute from [_currentTime.getTotalMinutes]
Expand Down Expand Up @@ -121,10 +121,10 @@ class _LiveTimeIndicatorState extends State<LiveTimeIndicator> {
showBullet: widget.liveTimeIndicatorSettings.showBullet,
showTime: widget.liveTimeIndicatorSettings.showTime,
showTimeBackgroundView:
widget.liveTimeIndicatorSettings.showTimeBackgroundView,
widget.liveTimeIndicatorSettings.showTimeBackgroundView,
bulletRadius: widget.liveTimeIndicatorSettings.bulletRadius,
timeBackgroundViewWidth:
widget.liveTimeIndicatorSettings.timeBackgroundViewWidth,
widget.liveTimeIndicatorSettings.timeBackgroundViewWidth,
),
);
}
Expand Down Expand Up @@ -167,6 +167,9 @@ class TimeLine extends StatefulWidget {
/// This field will be used to set end hour for day and week view
final int endHour;

/// This field will be optional if set true then the current timeline hour will be visible else default
final bool currentHourVisibility;

/// Time line to display time at left side of day or week view.
const TimeLine({
Key? key,
Expand All @@ -178,6 +181,7 @@ class TimeLine extends StatefulWidget {
required this.startHour,
this.showHalfHours = false,
this.showQuarterHours = false,
this.currentHourVisibility = false,
required this.liveTimeIndicatorSettings,
this.endHour = Constants.hoursADay,
}) : super(key: key);
Expand Down Expand Up @@ -228,49 +232,53 @@ class _TimeLineState extends State<TimeLine> {
children: [
for (int i = widget.startHour + 1; i < widget.endHour; i++)
_timelinePositioned(
topPosition: widget.hourHeight * (i - widget.startHour) -
widget.timeLineOffset,
bottomPosition: widget.height -
(widget.hourHeight * (i - widget.startHour + 1)) +
widget.timeLineOffset,
hour: i,
),
if (widget.showHalfHours)
for (int i = widget.startHour; i < widget.endHour; i++)
_timelinePositioned(
topPosition: widget.hourHeight * (i - widget.startHour) -
widget.timeLineOffset +
widget._halfHourHeight,
widget.timeLineOffset,
bottomPosition: widget.height -
(widget.hourHeight * (i - widget.startHour + 1)) +
widget.timeLineOffset,
hour: i,
minutes: 30,
visibility: widget.currentHourVisibility
),
if (widget.showHalfHours)
for (int i = widget.startHour; i < widget.endHour; i++)
_timelinePositioned(
topPosition: widget.hourHeight * (i - widget.startHour) -
widget.timeLineOffset +
widget._halfHourHeight,
bottomPosition: widget.height -
(widget.hourHeight * (i - widget.startHour + 1)) +
widget.timeLineOffset,
hour: i,
minutes: 30,
visibility: widget.currentHourVisibility
),
if (widget.showQuarterHours)
for (int i = 0; i < widget.endHour; i++) ...[
/// this is for 15 minutes
_timelinePositioned(
topPosition: widget.hourHeight * i -
widget.timeLineOffset +
widget.hourHeight * 0.25,
bottomPosition: widget.height -
(widget.hourHeight * (i + 1)) +
widget.timeLineOffset,
hour: i,
minutes: 15,
topPosition: widget.hourHeight * i -
widget.timeLineOffset +
widget.hourHeight * 0.25,
bottomPosition: widget.height -
(widget.hourHeight * (i + 1)) +
widget.timeLineOffset,
hour: i,
minutes: 15,
visibility: widget.currentHourVisibility
),

/// this is for 45 minutes
_timelinePositioned(
topPosition: widget.hourHeight * i -
widget.timeLineOffset +
widget.hourHeight * 0.75,
bottomPosition: widget.height -
(widget.hourHeight * (i + 1)) +
widget.timeLineOffset,
hour: i,
minutes: 45,
topPosition: widget.hourHeight * i -
widget.timeLineOffset +
widget.hourHeight * 0.75,
bottomPosition: widget.height -
(widget.hourHeight * (i + 1)) +
widget.timeLineOffset,
hour: i,
minutes: 45,
visibility: widget.currentHourVisibility
),
],
],
Expand All @@ -285,13 +293,14 @@ class _TimeLineState extends State<TimeLine> {
required double topPosition,
required double bottomPosition,
required int hour,
bool visibility = false,
int minutes = 0,
}) {
return Visibility(
visible: !((_currentTime.minute >= 45 && _currentTime.hour == hour - 1) ||
(_currentTime.minute <= 15 && _currentTime.hour == hour)) ||
visible: visibility == false ? !((_currentTime.minute >= 45 && _currentTime.hour == hour - 1) ||
(_currentTime.minute <= 15 && _currentTime.hour == hour)) ||
!(widget.liveTimeIndicatorSettings.showTime ||
widget.liveTimeIndicatorSettings.showTimeBackgroundView),
widget.liveTimeIndicatorSettings.showTimeBackgroundView) : true,
child: Positioned(
top: topPosition,
left: 0,
Expand Down
25 changes: 15 additions & 10 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
/// Flag to keep scrollOffset of pages on page change
final bool keepScrollOffset;

/// Flag to keep the visibility of the current hour to be optional
final bool currentHourVisibility;

/// Defines a single day page.
const InternalDayViewPage({
Key? key,
Expand Down Expand Up @@ -173,6 +176,7 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
this.keepScrollOffset = false,
this.currentHourVisibility = false
}) : super(key: key);

@override
Expand Down Expand Up @@ -215,9 +219,9 @@ class _InternalDayViewPageState<T extends Object?>
fullDayEventList.isEmpty
? SizedBox.shrink()
: widget.fullDayEventBuilder(
widget.controller.getFullDayEvent(widget.date),
widget.date,
),
widget.controller.getFullDayEvent(widget.date),
widget.date,
),
Expanded(
child: SingleChildScrollView(
controller: widget.keepScrollOffset
Expand All @@ -241,7 +245,7 @@ class _InternalDayViewPageState<T extends Object?>
lineStyle: widget.hourIndicatorSettings.lineStyle,
dashWidth: widget.hourIndicatorSettings.dashWidth,
dashSpaceWidth:
widget.hourIndicatorSettings.dashSpaceWidth,
widget.hourIndicatorSettings.dashSpaceWidth,
emulateVerticalOffsetBy: widget.emulateVerticalOffsetBy,
startHour: widget.startHour,
endHour: widget.endHour,
Expand All @@ -259,7 +263,7 @@ class _InternalDayViewPageState<T extends Object?>
lineStyle: widget.halfHourIndicatorSettings.lineStyle,
dashWidth: widget.halfHourIndicatorSettings.dashWidth,
dashSpaceWidth:
widget.halfHourIndicatorSettings.dashSpaceWidth,
widget.halfHourIndicatorSettings.dashSpaceWidth,
startHour: widget.startHour,
endHour: widget.endHour,
),
Expand All @@ -270,14 +274,14 @@ class _InternalDayViewPageState<T extends Object?>
painter: QuarterHourLinePainter(
lineColor: widget.quarterHourIndicatorSettings.color,
lineHeight:
widget.quarterHourIndicatorSettings.height,
widget.quarterHourIndicatorSettings.height,
offset: widget.timeLineWidth +
widget.quarterHourIndicatorSettings.offset,
minuteHeight: widget.heightPerMinute,
lineStyle:
widget.quarterHourIndicatorSettings.lineStyle,
widget.quarterHourIndicatorSettings.lineStyle,
dashWidth:
widget.quarterHourIndicatorSettings.dashWidth,
widget.quarterHourIndicatorSettings.dashWidth,
dashSpaceWidth: widget
.quarterHourIndicatorSettings.dashSpaceWidth,
),
Expand Down Expand Up @@ -325,14 +329,15 @@ class _InternalDayViewPageState<T extends Object?>
showQuarterHours: widget.showQuarterHours,
key: ValueKey(widget.heightPerMinute),
liveTimeIndicatorSettings:
widget.liveTimeIndicatorSettings,
widget.liveTimeIndicatorSettings,
currentHourVisibility: widget.currentHourVisibility,
),
if (widget.showLiveLine &&
widget.liveTimeIndicatorSettings.height > 0)
IgnorePointer(
child: LiveTimeIndicator(
liveTimeIndicatorSettings:
widget.liveTimeIndicatorSettings,
widget.liveTimeIndicatorSettings,
width: widget.width,
height: widget.height,
heightPerMinute: widget.heightPerMinute,
Expand Down
Loading

0 comments on commit ca92736

Please sign in to comment.