Skip to content

Commit

Permalink
Merge branch 'master' into customize_scrollphysics_monthview
Browse files Browse the repository at this point in the history
* master:
  feat: Added a callback for the default header title for all view #241.
  fix: 🐛Day view auto scroll to initial duration when using [scrollOffset] & [startingDuration] #269.
  Fixed issue with overlapping events
  formatted changes
  Updated default hourLineBuilder
  Updated Docs
  Fixed horizontal offset
  Added custom hour line painter functionality
  • Loading branch information
dumazy committed Nov 8, 2023
2 parents 4aeaf00 + 2ef1d21 commit 49b8936
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 79 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# [1.0.5] (UnReleased)(https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.5)

- Fixed issue related to auto scroll to initial duration for day
view-[#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269)
- Added
feature added a callback for the default header title
- [#241](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/241)

# [1.0.4 - 9 Aug 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.4)

- Fixed
Expand All @@ -8,10 +16,9 @@
Issue [#237 - DayView & MonthView layout issue in landscape mode](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/237)
- Added Feature
[#57 - Change default start hour in DayView](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/57)
- Fixed
- Fixed
Issue [#225 - Unwanted space at top in DayView while using sliver](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/225)


# [1.0.3 - 3 Apr 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.3)

- Added
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ DayView(
eventArranger: SideEventArranger(), // To define how simultaneous events will be arranged.
onEventTap: (events, date) => print(events),
onDateLongPress: (date) => print(date),
hourLinePainter: (lineColor, lineHeight, offset, minuteHeight, showVerticalLine, verticalLineOffset) {
return //Your custom painter.
}
);
```

Expand All @@ -200,9 +203,15 @@ WeekView(
onEventTap: (events, date) => print(events),
onDateLongPress: (date) => print(date),
startDay: WeekDays.sunday, // To change the first day of the week.
showVerticalLines: false, // Show the vertical line between days.
hourLinePainter: (lineColor, lineHeight, offset, minuteHeight, showVerticalLine, verticalLineOffset) {
return //Your custom painter.
}
);
```



To see the list of all parameters and detailed description of parameters
visit [documentation](https://pub.dev/documentation/calendar_view/latest/calendar_view/calendar_view-library.html)
.
Expand Down
24 changes: 14 additions & 10 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
/// Settings for hour indicator lines.
final HourIndicatorSettings hourIndicatorSettings;

/// Custom painter for hour line.
final CustomHourLinePainter hourLinePainter;

/// Flag to display live time indicator.
/// If true then indicator will be displayed else not.
final bool showLiveLine;
Expand Down Expand Up @@ -110,6 +113,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
required this.controller,
required this.timeLineBuilder,
required this.hourIndicatorSettings,
required this.hourLinePainter,
required this.showLiveLine,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute,
Expand Down Expand Up @@ -152,16 +156,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 Down
89 changes: 67 additions & 22 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../event_arrangers/event_arrangers.dart';
import '../event_controller.dart';
import '../extensions.dart';
import '../modals.dart';
import '../painters.dart';
import '../style/header_style.dart';
import '../typedefs.dart';
import '_internal_day_view_page.dart';
Expand Down Expand Up @@ -79,6 +80,11 @@ class DayView<T extends Object?> extends StatefulWidget {
/// Pass [HourIndicatorSettings.none] to remove Hour lines.
final HourIndicatorSettings? hourIndicatorSettings;

/// A funtion that returns a [CustomPainter].
///
/// Use this if you want to paint custom hour lines.
final CustomHourLinePainter? hourLinePainter;

/// Defines settings for live time indicator.
///
/// Pass [HourIndicatorSettings.none] to remove live time indicator.
Expand Down Expand Up @@ -145,8 +151,12 @@ class DayView<T extends Object?> extends StatefulWidget {
/// Background colour of day view page.
final Color? backgroundColor;

/// Scroll offset of day view page.
final double scrollOffset;
/// Defines initial offset of first page that will be displayed when
/// [DayView] is initialized.
///
/// If [scrollOffset] is null then [startDuration] will be considered for
/// initial offset.
final double? scrollOffset;

/// This method will be called when user taps on event tile.
final CellTapCallback<T>? onEventTap;
Expand Down Expand Up @@ -184,10 +194,13 @@ class DayView<T extends Object?> extends StatefulWidget {

final bool showHalfHours;

/// Duration from where default day view will be visible
/// It define the starting duration from where day view page will be visible
/// By default it will be Duration(hours:0)
final Duration startDuration;

/// Callback for the Header title
final HeaderTitleCallback? onHeaderTitleTap;

/// Main widget for day view.
const DayView({
Key? key,
Expand All @@ -203,6 +216,7 @@ class DayView<T extends Object?> extends StatefulWidget {
this.maxDay,
this.initialDay,
this.hourIndicatorSettings,
this.hourLinePainter,
this.heightPerMinute = 0.7,
this.timeLineBuilder,
this.timeLineWidth,
Expand All @@ -214,7 +228,7 @@ class DayView<T extends Object?> extends StatefulWidget {
this.eventArranger,
this.verticalLineOffset = 10,
this.backgroundColor = Colors.white,
this.scrollOffset = 0.0,
this.scrollOffset,
this.onEventTap,
this.onDateLongPress,
this.onDateTap,
Expand All @@ -228,7 +242,10 @@ class DayView<T extends Object?> extends StatefulWidget {
this.showHalfHours = false,
this.halfHourIndicatorSettings,
this.startDuration = const Duration(hours: 0),
}) : assert(timeLineOffset >= 0,
this.onHeaderTitleTap,
}) : assert(!(onHeaderTitleTap != null && dayTitleBuilder != null),
"can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"),
assert(timeLineOffset >= 0,
"timeLineOffset must be greater than or equal to 0"),
assert(width == null || width > 0,
"Calendar width must be greater than 0."),
Expand Down Expand Up @@ -262,6 +279,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {

late HourIndicatorSettings _hourIndicatorSettings;
late HourIndicatorSettings _halfHourIndicatorSettings;
late CustomHourLinePainter _hourLinePainter;

late HourIndicatorSettings _liveTimeIndicatorSettings;

late PageController _pageController;
Expand Down Expand Up @@ -298,8 +317,9 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
_regulateCurrentDate();

_calculateHeights();
_scrollController =
ScrollController(initialScrollOffset: widget.scrollOffset);
_scrollController = ScrollController(
initialScrollOffset: widget.scrollOffset ??
widget.startDuration.inMinutes * widget.heightPerMinute);
_pageController = PageController(initialPage: _currentIndex);
_eventArranger = widget.eventArranger ?? SideEventArranger<T>();
_assignBuilders();
Expand All @@ -323,10 +343,6 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
// user adds new events.
..addListener(_reloadCallback);
}

WidgetsBinding.instance.addPostFrameCallback((_) {
animateToDuration(widget.startDuration);
});
}

@override
Expand Down Expand Up @@ -407,6 +423,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
eventTileBuilder: _eventTileBuilder,
heightPerMinute: widget.heightPerMinute,
hourIndicatorSettings: _hourIndicatorSettings,
hourLinePainter: _hourLinePainter,
date: date,
onTileTap: widget.onEventTap,
onDateLongPress: widget.onDateLongPress,
Expand Down Expand Up @@ -510,6 +527,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
widget.fullDayEventBuilder ?? _defaultFullDayEventBuilder;
_dayDetectorBuilder =
widget.dayDetectorBuilder ?? _defaultPressDetectorBuilder;
_hourLinePainter = widget.hourLinePainter ?? _defaultHourLinePainter;
}

/// Sets the current date of this month.
Expand Down Expand Up @@ -638,15 +656,19 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
onNextDay: nextPage,
onPreviousDay: previousPage,
onTitleTapped: () async {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToDate(selectedDate);
if (widget.onHeaderTitleTap != null) {
widget.onHeaderTitleTap!(date);
} else {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToDate(selectedDate);
}
},
headerStyle: widget.headerStyle,
);
Expand All @@ -656,6 +678,30 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
List<CalendarEventData<T>> events, DateTime date) =>
FullDayEventView(events: events, date: date);

HourLinePainter _defaultHourLinePainter(
Color lineColor,
double lineHeight,
double offset,
double minuteHeight,
bool showVerticalLine,
double verticalLineOffset,
LineStyle lineStyle,
double dashWidth,
double dashSpaceWidth,
) {
return HourLinePainter(
lineColor: lineColor,
lineHeight: lineHeight,
offset: offset,
minuteHeight: minuteHeight,
verticalLineOffset: verticalLineOffset,
showVerticalLine: showVerticalLine,
lineStyle: lineStyle,
dashWidth: dashWidth,
dashSpaceWidth: dashSpaceWidth,
);
}

/// Called when user change page using any gesture or inbuilt functions.
///
void _onPageChange(int index) {
Expand Down Expand Up @@ -799,8 +845,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
// above 24 hrs then we take it max as 24 hours only
final offset = offSetForSingleMinute *
(startDurationInMinutes > 3600 ? 3600 : startDurationInMinutes);
debugPrint("offSet $offset");
_scrollController.animateTo(
animateTo(
offset.toDouble(),
duration: duration,
curve: curve,
Expand Down
7 changes: 6 additions & 1 deletion lib/src/event_arrangers/merge_event_arranger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {

bool _checkIsOverlapping(int arrangedEventStart, int arrangedEventEnd,
int eventStart, int eventEnd) {
return (arrangedEventStart >= eventStart &&
var result = (arrangedEventStart >= eventStart &&
arrangedEventStart <= eventEnd) ||
(arrangedEventEnd >= eventStart && arrangedEventEnd <= eventEnd) ||
(eventStart >= arrangedEventStart && eventStart <= arrangedEventEnd) ||
(eventEnd >= arrangedEventStart && eventEnd <= arrangedEventEnd);

if (result) {
result = result && (arrangedEventEnd != eventStart);
}
return result;
}
}
28 changes: 19 additions & 9 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// Option for SafeArea.
final SafeAreaOption safeAreaOption;

/// Callback for the Header title
final HeaderTitleCallback? onHeaderTitleTap;

/// Defines scroll physics for a page of a month view.
///
/// This can be used to disable the vertical scroll of a page.
Expand Down Expand Up @@ -172,8 +175,11 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.weekDayStringBuilder,
this.headerStyle = const HeaderStyle(),
this.safeAreaOption = const SafeAreaOption(),
this.onHeaderTitleTap,
this.pagePhysics = const ClampingScrollPhysics(),
}) : super(key: key);
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
"can't use [onHeaderTitleTap] & [headerBuilder] simultaneously"),
super(key: key);

@override
MonthViewState<T> createState() => MonthViewState<T>();
Expand Down Expand Up @@ -470,15 +476,19 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
Widget _defaultHeaderBuilder(DateTime date) {
return MonthPageHeader(
onTitleTapped: () async {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);
if (widget.onHeaderTitleTap != null) {
widget.onHeaderTitleTap!(date);
} else {
final selectedDate = await showDatePicker(
context: context,
initialDate: date,
firstDate: _minDate,
lastDate: _maxDate,
);

if (selectedDate == null) return;
jumpToMonth(selectedDate);
if (selectedDate == null) return;
jumpToMonth(selectedDate);
}
},
onPreviousMonth: previousPage,
date: date,
Expand Down
Loading

0 comments on commit 49b8936

Please sign in to comment.