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 d9071b6 commit d25452d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 48 deletions.
7 changes: 6 additions & 1 deletion lib/src/components/common_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:flutter/material.dart';

import '../calendar_event_data.dart';
import '../constants.dart';
import '../enumerations.dart';
import '../extensions.dart';
import '../style/header_style.dart';
import '../typedefs.dart';
import '../enumerations.dart';
import 'components.dart';

class CalendarPageHeader extends StatelessWidget {
Expand Down Expand Up @@ -172,6 +172,11 @@ class DefaultPressDetector extends StatelessWidget {
child: SizedBox(
width: width,
height: heightPerSlot,
child: kDebugMode
? ColoredBox(
color: Colors.red.withOpacity(0.2),
)
: SizedBox.shrink(),
),
),
),
Expand Down
49 changes: 26 additions & 23 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style license
// that can be found in the LICENSE file.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../components/_internal_components.dart';
Expand Down Expand Up @@ -241,24 +242,23 @@ class _InternalDayViewPageState<T extends Object?>
// Shows line for one hour.
CustomPaint(
size: Size(widget.width, widget.height),
painter: HourLinePainter(
lineColor: widget.hourIndicatorSettings.color,
lineHeight: widget.hourIndicatorSettings.height,
offset: widget.timeLineWidth +
painter: widget.hourLinePainter(
widget.hourIndicatorSettings.color,
widget.hourIndicatorSettings.height,
widget.timeLineWidth +
widget.hourIndicatorSettings.offset,
minuteHeight: widget.heightPerMinute,
verticalLineOffset: widget.verticalLineOffset,
showVerticalLine: widget.showVerticalLine,
lineStyle: widget.hourIndicatorSettings.lineStyle,
dashWidth: widget.hourIndicatorSettings.dashWidth,
dashSpaceWidth:
widget.hourIndicatorSettings.dashSpaceWidth,
emulateVerticalOffsetBy: widget.emulateVerticalOffsetBy,
startHour: widget.startHour,
endHour: widget.endHour,
padding: widget.pagePadding,
showEndHour: widget.showEndHours,
showStartHour: widget.showStartHours,
widget.heightPerMinute,
widget.showVerticalLine,
widget.verticalLineOffset,
widget.hourIndicatorSettings.lineStyle,
widget.hourIndicatorSettings.dashWidth,
widget.hourIndicatorSettings.dashSpaceWidth,
widget.emulateVerticalOffsetBy,
widget.startHour,
widget.endHour,
widget.showStartHours,
widget.showEndHours,
widget.pagePadding,
),
),
// Shows lines for Half hours
Expand Down Expand Up @@ -306,12 +306,15 @@ class _InternalDayViewPageState<T extends Object?>
//#endregion

// Enables gesture in empty areas.
widget.dayDetectorBuilder(
width: widget.width,
height: widget.height,
heightPerMinute: widget.heightPerMinute,
date: widget.date,
minuteSlotSize: widget.minuteSlotSize,
Padding(
padding: widget.pagePadding,
child: widget.dayDetectorBuilder(
width: widget.width,
height: widget.height,
heightPerMinute: widget.heightPerMinute,
date: widget.date,
minuteSlotSize: widget.minuteSlotSize,
),
),
Align(
alignment: Alignment.centerRight,
Expand Down
16 changes: 12 additions & 4 deletions lib/src/painters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class HourLinePainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final startOffset = padding.top;
final dx = offset + emulateVerticalOffsetBy;
final paint = Paint()
..color = lineColor
Expand All @@ -81,7 +82,8 @@ class HourLinePainter extends CustomPainter {
final end = endHour + (showEndHour ? 1 : 0);

for (var i = start; i < end; i++) {
final dy = (i - startHour) * minuteHeight * 60;
final dy = startOffset + ((i - startHour) * minuteHeight * 60);

if (lineStyle == LineStyle.dashed) {
var startX = dx;
while (startX < size.width) {
Expand Down Expand Up @@ -171,12 +173,16 @@ class HalfHourLinePainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final startOffset = padding.top;

final paint = Paint()
..color = lineColor
..strokeWidth = lineHeight;

for (var i = startHour; i < endHour; i++) {
final dy = (i - startHour) * minuteHeight * 60 + (minuteHeight * 30);
final dy = (i - startHour) * minuteHeight * 60 +
(minuteHeight * 30) +
startOffset;
if (lineStyle == LineStyle.dashed) {
var startX = offset;
while (startX < size.width) {
Expand Down Expand Up @@ -243,13 +249,15 @@ class QuarterHourLinePainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
final startOffset = padding.top;

final paint = Paint()
..color = lineColor
..strokeWidth = lineHeight;

for (var i = 0; i < Constants.hoursADay; i++) {
final dy1 = i * minuteHeight * 60 + (minuteHeight * 15);
final dy2 = i * minuteHeight * 60 + (minuteHeight * 45);
final dy1 = i * minuteHeight * 60 + (minuteHeight * 15) + startOffset;
final dy2 = i * minuteHeight * 60 + (minuteHeight * 45) + startOffset;

if (lineStyle == LineStyle.dashed) {
var startX = offset;
Expand Down
46 changes: 26 additions & 20 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,21 +354,23 @@ class _InternalWeekViewPageState<T extends Object?>
children: [
CustomPaint(
size: Size(widget.width, widget.height),
painter: HourLinePainter(
lineColor: widget.hourIndicatorSettings.color,
lineHeight: widget.hourIndicatorSettings.height,
offset: widget.timeLineWidth +
painter: widget.hourLinePainter(
widget.hourIndicatorSettings.color,
widget.hourIndicatorSettings.height,
widget.timeLineWidth +
widget.hourIndicatorSettings.offset,
minuteHeight: widget.heightPerMinute,
verticalLineOffset: widget.verticalLineOffset,
showVerticalLine: widget.showVerticalLine,
startHour: widget.startHour,
emulateVerticalOffsetBy:
widget.emulateVerticalOffsetBy,
endHour: widget.endHour,
padding: widget.pagePadding,
showEndHour: widget.showEndHours,
showStartHour: widget.showStartHours,
widget.heightPerMinute,
widget.showVerticalLine,
widget.verticalLineOffset,
widget.hourIndicatorSettings.lineStyle,
widget.hourIndicatorSettings.dashWidth,
widget.hourIndicatorSettings.dashSpaceWidth,
widget.emulateVerticalOffsetBy,
widget.startHour,
widget.endHour,
widget.showStartHours,
widget.showEndHours,
widget.pagePadding,
),
),
if (widget.showHalfHours)
Expand Down Expand Up @@ -442,12 +444,16 @@ class _InternalWeekViewPageState<T extends Object?>
width: widget.weekTitleWidth,
child: Stack(
children: [
widget.weekDetectorBuilder(
width: widget.weekTitleWidth,
height: widget.height,
heightPerMinute: widget.heightPerMinute,
date: widget.dates[index],
minuteSlotSize: widget.minuteSlotSize,
Padding(
padding: widget.pagePadding,
child: widget.weekDetectorBuilder(
width: widget.weekTitleWidth,
height: widget.height,
heightPerMinute:
widget.heightPerMinute,
date: widget.dates[index],
minuteSlotSize: widget.minuteSlotSize,
),
),
EventGenerator<T>(
height: widget.height,
Expand Down

0 comments on commit d25452d

Please sign in to comment.