Skip to content

Commit

Permalink
Updated default hourLineBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
werner-scholtz committed Aug 9, 2023
1 parent 3aec9a5 commit 498bed2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 115 deletions.
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 @@ -10,6 +10,7 @@ import '../enumerations.dart';
import '../event_arrangers/event_arrangers.dart';
import '../event_controller.dart';
import '../modals.dart';
import '../painters.dart';
import '../typedefs.dart';

/// Defines a single day page.
Expand Down Expand Up @@ -152,16 +153,16 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
children: [
CustomPaint(
size: Size(width, height),
painter: HourLinePainter(
lineColor: hourIndicatorSettings.color,
lineHeight: hourIndicatorSettings.height,
offset: timeLineWidth + hourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
verticalLineOffset: verticalLineOffset,
showVerticalLine: showVerticalLine,
lineStyle: hourIndicatorSettings.lineStyle,
dashWidth: hourIndicatorSettings.dashWidth,
dashSpaceWidth: hourIndicatorSettings.dashSpaceWidth,
painter: hourLinePainter(
hourIndicatorSettings.color,
hourIndicatorSettings.height,
timeLineWidth + hourIndicatorSettings.offset,
heightPerMinute,
showVerticalLine,
verticalLineOffset,
hourIndicatorSettings.lineStyle,
hourIndicatorSettings.dashWidth,
hourIndicatorSettings.dashSpaceWidth,
),
),
if (showHalfHours)
Expand All @@ -170,13 +171,11 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
painter: HalfHourLinePainter(
lineColor: halfHourIndicatorSettings.color,
lineHeight: halfHourIndicatorSettings.height,
offset:
timeLineWidth + halfHourIndicatorSettings.offset,
offset: timeLineWidth + halfHourIndicatorSettings.offset,
minuteHeight: heightPerMinute,
lineStyle: halfHourIndicatorSettings.lineStyle,
dashWidth: halfHourIndicatorSettings.dashWidth,
dashSpaceWidth:
halfHourIndicatorSettings.dashSpaceWidth,
dashSpaceWidth: halfHourIndicatorSettings.dashSpaceWidth,
),
),
dayDetectorBuilder(
Expand Down
69 changes: 29 additions & 40 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,11 @@ class DayView<T extends Object?> extends StatefulWidget {
this.showHalfHours = false,
this.halfHourIndicatorSettings,
this.startDuration = const Duration(hours: 0),
}) : assert(timeLineOffset >= 0,
"timeLineOffset must be greater than or equal to 0"),
assert(width == null || width > 0,
"Calendar width must be greater than 0."),
assert(timeLineWidth == null || timeLineWidth > 0,
"Time line width must be greater than 0."),
}) : assert(timeLineOffset >= 0, "timeLineOffset must be greater than or equal to 0"),
assert(width == null || width > 0, "Calendar width must be greater than 0."),
assert(
heightPerMinute > 0, "Height per minute must be greater than 0."),
timeLineWidth == null || timeLineWidth > 0, "Time line width must be greater than 0."),
assert(heightPerMinute > 0, "Height per minute must be greater than 0."),
assert(
dayDetectorBuilder == null || onDateLongPress == null,
"""If you use [dayPressDetectorBuilder]
Expand Down Expand Up @@ -307,8 +304,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
_regulateCurrentDate();

_calculateHeights();
_scrollController =
ScrollController(initialScrollOffset: widget.scrollOffset);
_scrollController = ScrollController(initialScrollOffset: widget.scrollOffset);
_pageController = PageController(initialPage: _currentIndex);
_eventArranger = widget.eventArranger ?? SideEventArranger<T>();
_assignBuilders();
Expand All @@ -318,8 +314,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
void didChangeDependencies() {
super.didChangeDependencies();

final newController = widget.controller ??
CalendarControllerProvider.of<T>(context).controller;
final newController = widget.controller ?? CalendarControllerProvider.of<T>(context).controller;

if (newController != _controller) {
_controller = newController;
Expand All @@ -342,8 +337,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
void didUpdateWidget(DayView<T> oldWidget) {
super.didUpdateWidget(oldWidget);
// Update controller.
final newController = widget.controller ??
CalendarControllerProvider.of<T>(context).controller;
final newController = widget.controller ?? CalendarControllerProvider.of<T>(context).controller;

if (newController != _controller) {
_controller?.removeListener(_reloadCallback);
Expand All @@ -352,8 +346,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
}

// Update date range.
if (widget.minDay != oldWidget.minDay ||
widget.maxDay != oldWidget.maxDay) {
if (widget.minDay != oldWidget.minDay || widget.maxDay != oldWidget.maxDay) {
_setDateRange();
_regulateCurrentDate();

Expand Down Expand Up @@ -401,23 +394,20 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
controller: _pageController,
onPageChanged: _onPageChange,
itemBuilder: (_, index) {
final date = DateTime(_minDate.year, _minDate.month,
_minDate.day + index);
final date = DateTime(_minDate.year, _minDate.month, _minDate.day + index);
return ValueListenableBuilder(
valueListenable: _scrollConfiguration,
builder: (_, __, ___) => InternalDayViewPage<T>(
key: ValueKey(
_hourHeight.toString() + date.toString()),
key: ValueKey(_hourHeight.toString() + date.toString()),
width: _width,
liveTimeIndicatorSettings:
_liveTimeIndicatorSettings,
liveTimeIndicatorSettings: _liveTimeIndicatorSettings,
timeLineBuilder: _timeLineBuilder,
dayDetectorBuilder: _dayDetectorBuilder,
eventTileBuilder: _eventTileBuilder,
heightPerMinute: widget.heightPerMinute,
hourIndicatorSettings: _hourIndicatorSettings,
hourLinePainter: _hourLinePainter,
date: date,
date: date,
onTileTap: widget.onEventTap,
onDateLongPress: widget.onDateLongPress,
onDateTap: widget.onDateTap,
Expand All @@ -436,8 +426,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
fullDayEventBuilder: _fullDayEventBuilder,
scrollController: _scrollController,
showHalfHours: widget.showHalfHours,
halfHourIndicatorSettings:
_halfHourIndicatorSettings,
halfHourIndicatorSettings: _halfHourIndicatorSettings,
),
);
},
Expand Down Expand Up @@ -516,10 +505,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
_timeLineBuilder = widget.timeLineBuilder ?? _defaultTimeLineBuilder;
_eventTileBuilder = widget.eventTileBuilder ?? _defaultEventTileBuilder;
_dayTitleBuilder = widget.dayTitleBuilder ?? _defaultDayBuilder;
_fullDayEventBuilder =
widget.fullDayEventBuilder ?? _defaultFullDayEventBuilder;
_dayDetectorBuilder =
widget.dayDetectorBuilder ?? _defaultPressDetectorBuilder;
_fullDayEventBuilder = widget.fullDayEventBuilder ?? _defaultFullDayEventBuilder;
_dayDetectorBuilder = widget.dayDetectorBuilder ?? _defaultPressDetectorBuilder;
_hourLinePainter = widget.hourLinePainter ?? _defaultHourLinePainter;
}

Expand Down Expand Up @@ -610,8 +597,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
/// Default timeline builder this builder will be used if
/// [widget.eventTileBuilder] is null
///
Widget _defaultTimeLineBuilder(date) => DefaultTimeLineMark(
date: date, timeStringBuilder: widget.timeStringBuilder);
Widget _defaultTimeLineBuilder(date) =>
DefaultTimeLineMark(date: date, timeStringBuilder: widget.timeStringBuilder);

/// Default timeline builder. This builder will be used if
/// [widget.eventTileBuilder] is null
Expand Down Expand Up @@ -663,8 +650,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
);
}

Widget _defaultFullDayEventBuilder(
List<CalendarEventData<T>> events, DateTime date) =>
Widget _defaultFullDayEventBuilder(List<CalendarEventData<T>> events, DateTime date) =>
FullDayEventView(events: events, date: date);

HourLinePainter _defaultHourLinePainter(
Expand All @@ -674,6 +660,9 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
double minuteHeight,
bool showVerticalLine,
double verticalLineOffset,
LineStyle lineStyle,
double dashWidth,
double dashSpaceWidth,
) {
return HourLinePainter(
lineColor: lineColor,
Expand All @@ -682,6 +671,9 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
minuteHeight: minuteHeight,
verticalLineOffset: verticalLineOffset,
showVerticalLine: showVerticalLine,
lineStyle: lineStyle,
dashWidth: dashWidth,
dashSpaceWidth: dashSpaceWidth,
);
}

Expand Down Expand Up @@ -721,8 +713,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
/// respectively.
///
///
void previousPage({Duration? duration, Curve? curve}) =>
_pageController.previousPage(
void previousPage({Duration? duration, Curve? curve}) => _pageController.previousPage(
duration: duration ?? widget.pageTransitionDuration,
curve: curve ?? widget.pageTransitionCurve,
);
Expand Down Expand Up @@ -766,8 +757,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
/// respectively.
///
///
Future<void> animateToDate(DateTime date,
{Duration? duration, Curve? curve}) async {
Future<void> animateToDate(DateTime date, {Duration? duration, Curve? curve}) async {
if (date.isBefore(_minDate) || date.isAfter(_maxDate)) {
throw "Invalid date selected.";
}
Expand Down Expand Up @@ -826,8 +816,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {

// Added ternary condition below to take care if user passing duration
// above 24 hrs then we take it max as 24 hours only
final offset = offSetForSingleMinute *
(startDurationInMinutes > 3600 ? 3600 : startDurationInMinutes);
final offset =
offSetForSingleMinute * (startDurationInMinutes > 3600 ? 3600 : startDurationInMinutes);
debugPrint("offSet $offset");
_scrollController.animateTo(
offset.toDouble(),
Expand All @@ -850,6 +840,5 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
}

/// Returns the current visible date in day view.
DateTime get currentDate =>
DateTime(_currentDate.year, _currentDate.month, _currentDate.day);
DateTime get currentDate => DateTime(_currentDate.year, _currentDate.month, _currentDate.day);
}
12 changes: 6 additions & 6 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ typedef WeekNumberBuilder = Widget? Function(
DateTime firstDayOfWeek,
);

typedef FullDayEventBuilder<T> = Widget Function(
List<CalendarEventData<T>> events, DateTime date);
typedef FullDayEventBuilder<T> = Widget Function(List<CalendarEventData<T>> events, DateTime date);

typedef CalendarPageChangeCallBack = void Function(DateTime date, int page);

Expand All @@ -51,11 +50,9 @@ typedef PageChangeCallback = void Function(
CalendarEventData event,
);

typedef StringProvider = String Function(DateTime date,
{DateTime? secondaryDate});
typedef StringProvider = String Function(DateTime date, {DateTime? secondaryDate});

typedef WeekPageHeaderBuilder = Widget Function(
DateTime startDate, DateTime endDate);
typedef WeekPageHeaderBuilder = Widget Function(DateTime startDate, DateTime endDate);

typedef TileTapCallback<T extends Object?> = void Function(
CalendarEventData<T> event, DateTime date);
Expand All @@ -77,4 +74,7 @@ typedef CustomHourLinePainter = CustomPainter Function(
double minuteHeight,
bool showVerticalLine,
double verticalLineOffset,
LineStyle lineStyle,
double dashWidth,
double dashSpaceWidth,
);
3 changes: 3 additions & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
heightPerMinute,
showVerticalLine,
verticalLineOffset,
hourIndicatorSettings.lineStyle,
hourIndicatorSettings.dashWidth,
hourIndicatorSettings.dashSpaceWidth,
),
),
if (showLiveLine && liveTimeIndicatorSettings.height > 0)
Expand Down
Loading

0 comments on commit 498bed2

Please sign in to comment.