diff --git a/example/lib/widgets/day_view_widget.dart b/example/lib/widgets/day_view_widget.dart index 6d5d5784..88d77b25 100644 --- a/example/lib/widgets/day_view_widget.dart +++ b/example/lib/widgets/day_view_widget.dart @@ -25,6 +25,7 @@ class DayViewWidget extends StatelessWidget { hourIndicatorSettings: HourIndicatorSettings( color: Theme.of(context).dividerColor, ), + showQuarterHours: true, onEventTap: (events, date) { Navigator.of(context).push( MaterialPageRoute( @@ -44,7 +45,6 @@ class DayViewWidget extends StatelessWidget { ), verticalLineOffset: 0, timeLineWidth: 65, - showQuarterHours: true, showLiveTimeLineInAllDays: true, liveTimeIndicatorSettings: LiveTimeIndicatorSettings( color: Colors.redAccent, diff --git a/lib/src/components/_internal_components.dart b/lib/src/components/_internal_components.dart index 95ed0663..8ea0ef8e 100644 --- a/lib/src/components/_internal_components.dart +++ b/lib/src/components/_internal_components.dart @@ -173,6 +173,8 @@ class TimeLine extends StatefulWidget { /// Defines if we need to display the 0 hr and 24 hr text in time line or not. final bool showStartHours; + final EdgeInsets padding; + /// Time line to display time at left side of day or week view. const TimeLine({ Key? key, @@ -188,6 +190,7 @@ class TimeLine extends StatefulWidget { this.endHour = Constants.hoursADay, required this.showEndHours, required this.showStartHours, + required this.padding, }) : super(key: key); @override @@ -204,24 +207,6 @@ class _TimeLineState extends State { _timer = Timer.periodic(Duration(seconds: 1), _onTick); } - @override - void dispose() { - _timer.cancel(); - super.dispose(); - } - - /// Creates an recursive call that runs every 1 seconds. - /// This will rebuild TimeLine every second. This will allow us - /// to show/hide time line when there is overlap with - /// live time line indicator in Week and Day view. - void _onTick(Timer? timer) { - final time = TimeOfDay.now(); - if (time != _currentTime && mounted) { - _currentTime = time; - setState(() {}); - } - } - @override Widget build(BuildContext context) { return ConstrainedBox( @@ -239,10 +224,12 @@ class _TimeLineState extends State { i++) _timelinePositioned( topPosition: widget.hourHeight * (i - widget.startHour) - - widget.timeLineOffset, + widget.timeLineOffset + + widget.padding.top, bottomPosition: widget.height - (widget.hourHeight * (i - widget.startHour + 1)) + - widget.timeLineOffset, + widget.timeLineOffset - + widget.padding.bottom, hour: i, ), if (widget.showHalfHours) @@ -250,10 +237,12 @@ class _TimeLineState extends State { _timelinePositioned( topPosition: widget.hourHeight * (i - widget.startHour) - widget.timeLineOffset + - widget._halfHourHeight, + widget._halfHourHeight + + widget.padding.top, bottomPosition: widget.height - (widget.hourHeight * (i - widget.startHour + 1)) + - widget.timeLineOffset, + widget.timeLineOffset - + widget.padding.bottom, hour: i, minutes: 30, ), @@ -263,10 +252,12 @@ class _TimeLineState extends State { _timelinePositioned( topPosition: widget.hourHeight * i - widget.timeLineOffset + - widget.hourHeight * 0.25, + widget.hourHeight * 0.25 + + widget.padding.top, bottomPosition: widget.height - (widget.hourHeight * (i + 1)) + - widget.timeLineOffset, + widget.timeLineOffset - + widget.padding.bottom, hour: i, minutes: 15, ), @@ -275,10 +266,12 @@ class _TimeLineState extends State { _timelinePositioned( topPosition: widget.hourHeight * i - widget.timeLineOffset + - widget.hourHeight * 0.75, + widget.hourHeight * 0.75 + + widget.padding.top, bottomPosition: widget.height - (widget.hourHeight * (i + 1)) + - widget.timeLineOffset, + widget.timeLineOffset - + widget.padding.bottom, hour: i, minutes: 45, ), @@ -288,6 +281,24 @@ class _TimeLineState extends State { ); } + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + /// Creates an recursive call that runs every 1 seconds. + /// This will rebuild TimeLine every second. This will allow us + /// to show/hide time line when there is overlap with + /// live time line indicator in Week and Day view. + void _onTick(Timer? timer) { + final time = TimeOfDay.now(); + if (time != _currentTime && mounted) { + _currentTime = time; + setState(() {}); + } + } + /// To avoid overlap of live time line indicator, show time line when /// current min is less than 45 min and is previous hour or /// current min is greater than 15 min and is current hour @@ -307,7 +318,7 @@ class _TimeLineState extends State { left: 0, right: 0, bottom: bottomPosition, - child: Container( + child: SizedBox( height: widget.hourHeight, width: widget.timeLineWidth, child: widget.timeLineBuilder.call( diff --git a/lib/src/components/common_components.dart b/lib/src/components/common_components.dart index ccea5d96..4a22ecdf 100644 --- a/lib/src/components/common_components.dart +++ b/lib/src/components/common_components.dart @@ -134,6 +134,8 @@ class DefaultPressDetector extends StatelessWidget { this.onDateTap, this.onDateLongPress, this.startHour = 0, + required this.padding, + required this.endHour, }); final DateTime date; @@ -144,11 +146,13 @@ class DefaultPressDetector extends StatelessWidget { final DateTapCallback? onDateTap; final DatePressCallback? onDateLongPress; final int startHour; + final int endHour; + final EdgeInsets padding; @override Widget build(BuildContext context) { final heightPerSlot = minuteSlotSize.minutes * heightPerMinute; - final slots = (Constants.hoursADay * 60) ~/ minuteSlotSize.minutes; + final slots = ((endHour - startHour) * 60) ~/ minuteSlotSize.minutes; return SizedBox( height: height, @@ -157,10 +161,10 @@ class DefaultPressDetector extends StatelessWidget { children: [ for (int i = 0; i < slots; i++) Positioned( - top: heightPerSlot * i, + top: padding.top + heightPerSlot * i, left: 0, right: 0, - bottom: height - (heightPerSlot * (i + 1)), + bottom: height - (heightPerSlot * (i + 1)) - padding.bottom, child: GestureDetector( behavior: HitTestBehavior.translucent, onLongPress: () => onDateLongPress?.call( @@ -172,9 +176,6 @@ class DefaultPressDetector extends StatelessWidget { child: SizedBox( width: width, height: heightPerSlot, - child: kDebugMode - ? ColoredBox(color: Colors.red.withOpacity(0.1)) - : SizedBox.shrink(), ), ), ), diff --git a/lib/src/components/day_view_components.dart b/lib/src/components/day_view_components.dart index c9498ecf..ac4aa80b 100644 --- a/lib/src/components/day_view_components.dart +++ b/lib/src/components/day_view_components.dart @@ -177,13 +177,7 @@ class DefaultTimeLineMark extends StatelessWidget { : "$hour ${time.hour ~/ 12 == 0 ? "am" : "pm"}"; return Transform.translate( - offset: Offset( - 0, - time.hour == 0 && time.minute == 0 - ? -7.5 - : time.hour == 24 && time.minute == 0 - ? -18 - : -7.5), + offset: Offset(0, -8), child: Padding( padding: const EdgeInsets.only(right: 7.0), child: Text( diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index 7fb4fb3a..ca8a2ec0 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -306,23 +306,21 @@ class _InternalDayViewPageState //#endregion // Enables gesture in empty areas. - Padding( - padding: widget.pagePadding, - child: widget.dayDetectorBuilder( - width: widget.width, - height: widget.height, - heightPerMinute: widget.heightPerMinute, - date: widget.date, - minuteSlotSize: widget.minuteSlotSize, - ), + widget.dayDetectorBuilder( + width: widget.width, + height: widget.height, + heightPerMinute: widget.heightPerMinute, + date: widget.date, + minuteSlotSize: widget.minuteSlotSize, + pagePadding: widget.pagePadding, ), - Align( - alignment: Alignment.centerRight, - child: Padding( - padding: widget.pagePadding, + Padding( + padding: widget.pagePadding, + child: Align( + alignment: Alignment.centerRight, child: EventGenerator( - height: widget.height, + height: widget.height - widget.pagePadding.vertical, date: widget.date, onTileLongTap: widget.onTileLongTap, onTileDoubleTap: widget.onTileDoubleTap, @@ -358,6 +356,7 @@ class _InternalDayViewPageState liveTimeIndicatorSettings: widget.liveTimeIndicatorSettings, showEndHours: widget.showEndHours, showStartHours: widget.showStartHours, + padding: widget.pagePadding, ), if (widget.showLiveLine && widget.liveTimeIndicatorSettings.height > 0) diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index e8ed2deb..6cf393db 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -665,6 +665,7 @@ class DayViewState extends State> { required double width, required double heightPerMinute, required MinuteSlotSize minuteSlotSize, + required EdgeInsets pagePadding, }) => DefaultPressDetector( date: date, @@ -675,6 +676,8 @@ class DayViewState extends State> { onDateTap: widget.onDateTap, onDateLongPress: widget.onDateLongPress, startHour: widget.startHour, + endHour: widget.endHour, + padding: pagePadding, ); /// Default timeline builder this builder will be used if diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index 119e3bf8..23b982ca 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -28,6 +28,7 @@ typedef DetectorBuilder = Widget Function({ required double width, required double heightPerMinute, required MinuteSlotSize minuteSlotSize, + required EdgeInsets pagePadding, }); typedef WeekDayBuilder = Widget Function( diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index 719370fe..4e789df4 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -453,6 +453,7 @@ class _InternalWeekViewPageState widget.heightPerMinute, date: widget.dates[index], minuteSlotSize: widget.minuteSlotSize, + pagePadding: widget.pagePadding, ), ), EventGenerator( @@ -498,6 +499,7 @@ class _InternalWeekViewPageState endHour: widget.endHour, showEndHours: widget.showEndHours, showStartHours: widget.showStartHours, + padding: widget.pagePadding, ), if (widget.showLiveLine && widget.liveTimeIndicatorSettings.height > 0) diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index b6851f73..1835d551 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -758,6 +758,7 @@ class WeekViewState extends State> { required double width, required double heightPerMinute, required MinuteSlotSize minuteSlotSize, + required EdgeInsets pagePadding, }) => DefaultPressDetector( date: date, @@ -768,6 +769,8 @@ class WeekViewState extends State> { onDateTap: widget.onDateTap, onDateLongPress: widget.onDateLongPress, startHour: _startHour, + endHour: _endHour, + padding: pagePadding, ); /// Default builder for week line.