From cc7775978e243b39bd3ed5cd54ce53c97ff155f2 Mon Sep 17 00:00:00 2001 From: Parth Baraiya Date: Thu, 13 Jun 2024 16:51:13 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20update=20example=20to=20support=20l?= =?UTF-8?q?atest=20flutter=20versions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/widgets/day_view_widget.dart | 2 +- lib/src/components/_internal_components.dart | 24 ++++++++++++----- lib/src/components/common_components.dart | 13 ++++----- lib/src/day_view/_internal_day_view_page.dart | 27 +++++++++---------- lib/src/day_view/day_view.dart | 3 +++ lib/src/typedefs.dart | 1 + .../week_view/_internal_week_view_page.dart | 2 ++ lib/src/week_view/week_view.dart | 3 +++ 8 files changed, 47 insertions(+), 28 deletions(-) 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..039e93cc 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 @@ -239,10 +242,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 +255,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 +270,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, ), @@ -297,6 +306,7 @@ class _TimeLineState extends State { required int hour, int minutes = 0, }) { + debugPrint("Hour: $hour, Top: $topPosition, Bottom: $bottomPosition"); return Visibility( visible: !((_currentTime.minute >= 45 && _currentTime.hour == hour - 1) || (_currentTime.minute <= 15 && _currentTime.hour == hour)) || @@ -307,7 +317,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/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.