Skip to content

Commit

Permalink
✨ update example to support latest flutter versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthBaraiya committed Jun 13, 2024
1 parent 99bb35f commit cc77759
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 28 deletions.
2 changes: 1 addition & 1 deletion example/lib/widgets/day_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -44,7 +45,6 @@ class DayViewWidget extends StatelessWidget {
),
verticalLineOffset: 0,
timeLineWidth: 65,
showQuarterHours: true,
showLiveTimeLineInAllDays: true,
liveTimeIndicatorSettings: LiveTimeIndicatorSettings(
color: Colors.redAccent,
Expand Down
24 changes: 17 additions & 7 deletions lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -239,21 +242,25 @@ class _TimeLineState extends State<TimeLine> {
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)
for (int i = widget.startHour; i < widget.endHour; i++)
_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,
),
Expand All @@ -263,10 +270,12 @@ class _TimeLineState extends State<TimeLine> {
_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,
),
Expand Down Expand Up @@ -297,6 +306,7 @@ class _TimeLineState extends State<TimeLine> {
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)) ||
Expand All @@ -307,7 +317,7 @@ class _TimeLineState extends State<TimeLine> {
left: 0,
right: 0,
bottom: bottomPosition,
child: Container(
child: SizedBox(
height: widget.hourHeight,
width: widget.timeLineWidth,
child: widget.timeLineBuilder.call(
Expand Down
13 changes: 7 additions & 6 deletions lib/src/components/common_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class DefaultPressDetector extends StatelessWidget {
this.onDateTap,
this.onDateLongPress,
this.startHour = 0,
required this.padding,
required this.endHour,
});

final DateTime date;
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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(),
),
),
),
Expand Down
27 changes: 13 additions & 14 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,21 @@ class _InternalDayViewPageState<T extends Object?>
//#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<T>(
height: widget.height,
height: widget.height - widget.pagePadding.vertical,
date: widget.date,
onTileLongTap: widget.onTileLongTap,
onTileDoubleTap: widget.onTileDoubleTap,
Expand Down Expand Up @@ -358,6 +356,7 @@ class _InternalDayViewPageState<T extends Object?>
liveTimeIndicatorSettings: widget.liveTimeIndicatorSettings,
showEndHours: widget.showEndHours,
showStartHours: widget.showStartHours,
padding: widget.pagePadding,
),
if (widget.showLiveLine &&
widget.liveTimeIndicatorSettings.height > 0)
Expand Down
3 changes: 3 additions & 0 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
required double width,
required double heightPerMinute,
required MinuteSlotSize minuteSlotSize,
required EdgeInsets pagePadding,
}) =>
DefaultPressDetector(
date: date,
Expand All @@ -675,6 +676,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
onDateTap: widget.onDateTap,
onDateLongPress: widget.onDateLongPress,
startHour: widget.startHour,
endHour: widget.endHour,
padding: pagePadding,
);

/// Default timeline builder this builder will be used if
Expand Down
1 change: 1 addition & 0 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef DetectorBuilder<T extends Object?> = Widget Function({
required double width,
required double heightPerMinute,
required MinuteSlotSize minuteSlotSize,
required EdgeInsets pagePadding,
});

typedef WeekDayBuilder = Widget Function(
Expand Down
2 changes: 2 additions & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class _InternalWeekViewPageState<T extends Object?>
widget.heightPerMinute,
date: widget.dates[index],
minuteSlotSize: widget.minuteSlotSize,
pagePadding: widget.pagePadding,
),
),
EventGenerator<T>(
Expand Down Expand Up @@ -498,6 +499,7 @@ class _InternalWeekViewPageState<T extends Object?>
endHour: widget.endHour,
showEndHours: widget.showEndHours,
showStartHours: widget.showStartHours,
padding: widget.pagePadding,
),
if (widget.showLiveLine &&
widget.liveTimeIndicatorSettings.height > 0)
Expand Down
3 changes: 3 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
required double width,
required double heightPerMinute,
required MinuteSlotSize minuteSlotSize,
required EdgeInsets pagePadding,
}) =>
DefaultPressDetector(
date: date,
Expand All @@ -768,6 +769,8 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
onDateTap: widget.onDateTap,
onDateLongPress: widget.onDateLongPress,
startHour: _startHour,
endHour: _endHour,
padding: pagePadding,
);

/// Default builder for week line.
Expand Down

0 comments on commit cc77759

Please sign in to comment.