From 34fc8dbf1abd966a4676dec30d28b8b20ed28914 Mon Sep 17 00:00:00 2001 From: MohGawdat Date: Sat, 16 Sep 2023 23:45:53 +0300 Subject: [PATCH 1/8] Add RTL support for HourLine and HalfHourLine painters --- lib/src/day_view/_internal_day_view_page.dart | 26 ++++------ lib/src/painters.dart | 52 +++++++++++-------- .../week_view/_internal_week_view_page.dart | 15 +++--- 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index 706cf02c..2d7f5a5c 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -102,7 +102,7 @@ class InternalDayViewPage extends StatelessWidget { /// Defines a single day page. const InternalDayViewPage({ - Key? key, + super.key, required this.showVerticalLine, required this.width, required this.date, @@ -129,19 +129,19 @@ class InternalDayViewPage extends StatelessWidget { required this.dayDetectorBuilder, required this.showHalfHours, required this.halfHourIndicatorSettings, - }) : super(key: key); + }); @override Widget build(BuildContext context) { final fullDayEventList = controller.getFullDayEvent(date); - return Container( + final isRtl = Directionality.of(context) == TextDirection.rtl; + + return SizedBox( height: height, width: width, child: Column( children: [ - fullDayEventList.isEmpty - ? SizedBox.shrink() - : fullDayEventBuilder(fullDayEventList, date), + fullDayEventList.isEmpty ? const SizedBox.shrink() : fullDayEventBuilder(fullDayEventList, date), Expanded( child: SingleChildScrollView( controller: scrollController, @@ -162,6 +162,7 @@ class InternalDayViewPage extends StatelessWidget { lineStyle: hourIndicatorSettings.lineStyle, dashWidth: hourIndicatorSettings.dashWidth, dashSpaceWidth: hourIndicatorSettings.dashSpaceWidth, + isRtl: isRtl, ), ), if (showHalfHours) @@ -170,13 +171,11 @@ class InternalDayViewPage 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( @@ -187,7 +186,7 @@ class InternalDayViewPage extends StatelessWidget { minuteSlotSize: minuteSlotSize, ), Align( - alignment: Alignment.centerRight, + alignment: isRtl ? Alignment.centerLeft : Alignment.centerRight, // adjust alignment based on directionality child: EventGenerator( height: height, date: date, @@ -197,10 +196,7 @@ class InternalDayViewPage extends StatelessWidget { heightPerMinute: heightPerMinute, eventTileBuilder: eventTileBuilder, scrollNotifier: scrollNotifier, - width: width - - timeLineWidth - - hourIndicatorSettings.offset - - verticalLineOffset, + width: width - timeLineWidth - hourIndicatorSettings.offset - verticalLineOffset, ), ), TimeLine( diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 1c2a539b..27f41b40 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -36,6 +36,14 @@ class HourLinePainter extends CustomPainter { /// Line dash space width when using the [LineStyle.dashed] style final double dashSpaceWidth; + /// Indicates if the layout direction is right-to-left (RTL). + /// + /// This value is crucial for correctly drawing the table, especially + /// elements like the vertical line which change position based on + /// the layout direction. Pass this from parent contexts to ensure + /// accurate representation in RTL layouts. + final bool isRtl; + /// Paints 24 hour lines. HourLinePainter({ required this.lineColor, @@ -47,6 +55,7 @@ class HourLinePainter extends CustomPainter { this.lineStyle = LineStyle.solid, this.dashWidth = 4, this.dashSpaceWidth = 4, + required this.isRtl, }); @override @@ -55,30 +64,37 @@ class HourLinePainter extends CustomPainter { ..color = lineColor ..strokeWidth = lineHeight; + // Determine RTL + for (var i = 1; i < Constants.hoursADay; i++) { final dy = i * minuteHeight * 60; if (lineStyle == LineStyle.dashed) { var startX = offset; while (startX < size.width) { - canvas.drawLine( - Offset(startX, dy), Offset(startX + dashWidth, dy), paint); + canvas.drawLine(Offset(startX, dy), Offset(startX + dashWidth, dy), paint); startX += dashWidth + dashSpaceWidth; + if (isRtl && startX > size.width) break; // Stop drawing extra dashes } } else { - canvas.drawLine(Offset(offset, dy), Offset(size.width, dy), paint); + canvas.drawLine(Offset(isRtl ? size.width - offset : offset, dy), Offset(isRtl ? 0 : size.width, dy), paint); } } - if (showVerticalLine) if (lineStyle == LineStyle.dashed) { - var startY = 0.0; - while (startY < size.height) { - canvas.drawLine(Offset(offset + verticalLineOffset, startY), - Offset(offset + verticalLineOffset, startY + dashWidth), paint); - startY += dashWidth + dashSpaceWidth; + if (showVerticalLine) { + final verticalOffset = isRtl ? size.width - offset : offset; + if (lineStyle == LineStyle.dashed) { + var startY = 0.0; + while (startY < size.height) { + canvas.drawLine(Offset(verticalOffset + verticalLineOffset, startY), Offset(verticalOffset + verticalLineOffset, startY + dashWidth), paint); + startY += dashWidth + dashSpaceWidth; + } + } else { + canvas.drawLine( + Offset(verticalOffset, 0), + Offset(verticalOffset, size.height), + paint, + ); } - } else { - canvas.drawLine(Offset(offset + verticalLineOffset, 0), - Offset(offset + verticalLineOffset, size.height), paint); } } @@ -137,8 +153,7 @@ class HalfHourLinePainter extends CustomPainter { if (lineStyle == LineStyle.dashed) { var startX = offset; while (startX < size.width) { - canvas.drawLine( - Offset(startX, dy), Offset(startX + dashWidth, dy), paint); + canvas.drawLine(Offset(startX, dy), Offset(startX + dashWidth, dy), paint); startX += dashWidth + dashSpaceWidth; } } else { @@ -193,15 +208,10 @@ class CurrentTimeLinePainter extends CustomPainter { ..strokeWidth = height, ); - if (showBullet) - canvas.drawCircle( - Offset(offset.dx, offset.dy), bulletRadius, Paint()..color = color); + if (showBullet) canvas.drawCircle(Offset(offset.dx, offset.dy), bulletRadius, Paint()..color = color); } @override bool shouldRepaint(covariant CustomPainter oldDelegate) => - oldDelegate is CurrentTimeLinePainter && - (color != oldDelegate.color || - height != oldDelegate.height || - offset != oldDelegate.offset); + oldDelegate is CurrentTimeLinePainter && (color != oldDelegate.color || height != oldDelegate.height || offset != oldDelegate.offset); } diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index 3f7ec3b4..a5ab36db 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -148,7 +148,9 @@ class InternalWeekViewPage extends StatelessWidget { @override Widget build(BuildContext context) { final filteredDates = _filteredDate(); - return Container( + final isRtl = Directionality.of(context) == TextDirection.rtl; + + return SizedBox( height: height + weekTitleHeight, width: width, child: Column( @@ -177,7 +179,7 @@ class InternalWeekViewPage extends StatelessWidget { ], ), ), - Divider( + const Divider( thickness: 1, height: 1, ), @@ -190,10 +192,9 @@ class InternalWeekViewPage extends StatelessWidget { ...List.generate( filteredDates.length, (index) { - final fullDayEventList = - controller.getFullDayEvent(filteredDates[index]); + final fullDayEventList = controller.getFullDayEvent(filteredDates[index]); return fullDayEventList.isEmpty - ? SizedBox.shrink() + ? const SizedBox.shrink() : SizedBox( width: weekTitleWidth, child: fullDayEventBuilder.call( @@ -217,6 +218,7 @@ class InternalWeekViewPage extends StatelessWidget { CustomPaint( size: Size(width, height), painter: HourLinePainter( + isRtl: isRtl, lineColor: hourIndicatorSettings.color, lineHeight: hourIndicatorSettings.height, offset: timeLineWidth + hourIndicatorSettings.offset, @@ -270,8 +272,7 @@ class InternalWeekViewPage extends StatelessWidget { eventArranger: eventArranger, eventTileBuilder: eventTileBuilder, scrollNotifier: scrollConfiguration, - events: controller - .getEventsOnDay(filteredDates[index]), + events: controller.getEventsOnDay(filteredDates[index]), heightPerMinute: heightPerMinute, ), ], From 5c0e07980f4cb15727a4a8f54ed5f0a0607b9541 Mon Sep 17 00:00:00 2001 From: Gawdat Date: Sun, 17 Sep 2023 11:36:17 +0300 Subject: [PATCH 2/8] fix: formatting --- lib/src/day_view/_internal_day_view_page.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index 2d7f5a5c..2dee5248 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -102,7 +102,7 @@ class InternalDayViewPage extends StatelessWidget { /// Defines a single day page. const InternalDayViewPage({ - super.key, + Key? key, required this.showVerticalLine, required this.width, required this.date, @@ -129,19 +129,19 @@ class InternalDayViewPage extends StatelessWidget { required this.dayDetectorBuilder, required this.showHalfHours, required this.halfHourIndicatorSettings, - }); + }) : super(key: key); @override Widget build(BuildContext context) { final fullDayEventList = controller.getFullDayEvent(date); final isRtl = Directionality.of(context) == TextDirection.rtl; - return SizedBox( + return Container( height: height, width: width, child: Column( children: [ - fullDayEventList.isEmpty ? const SizedBox.shrink() : fullDayEventBuilder(fullDayEventList, date), + fullDayEventList.isEmpty ? SizedBox.shrink() : fullDayEventBuilder(fullDayEventList, date), Expanded( child: SingleChildScrollView( controller: scrollController, From 1f1df866a7d00c6b94306ac0e9f8b3280e4be353 Mon Sep 17 00:00:00 2001 From: Gawdat Date: Sun, 17 Sep 2023 11:37:51 +0300 Subject: [PATCH 3/8] fix: formatting --- lib/src/week_view/_internal_week_view_page.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index a5ab36db..ca9ca542 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -150,7 +150,7 @@ class InternalWeekViewPage extends StatelessWidget { final filteredDates = _filteredDate(); final isRtl = Directionality.of(context) == TextDirection.rtl; - return SizedBox( + return Container( height: height + weekTitleHeight, width: width, child: Column( @@ -179,7 +179,7 @@ class InternalWeekViewPage extends StatelessWidget { ], ), ), - const Divider( + Divider( thickness: 1, height: 1, ), @@ -194,7 +194,7 @@ class InternalWeekViewPage extends StatelessWidget { (index) { final fullDayEventList = controller.getFullDayEvent(filteredDates[index]); return fullDayEventList.isEmpty - ? const SizedBox.shrink() + ? SizedBox.shrink() : SizedBox( width: weekTitleWidth, child: fullDayEventBuilder.call( From 8ec2a68714be71ba20542cb3a1be0d7225bfae07 Mon Sep 17 00:00:00 2001 From: Gawdat Date: Sun, 17 Sep 2023 11:39:36 +0300 Subject: [PATCH 4/8] fix: formatting --- lib/src/painters.dart | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 27f41b40..685595be 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -64,8 +64,6 @@ class HourLinePainter extends CustomPainter { ..color = lineColor ..strokeWidth = lineHeight; - // Determine RTL - for (var i = 1; i < Constants.hoursADay; i++) { final dy = i * minuteHeight * 60; if (lineStyle == LineStyle.dashed) { @@ -89,11 +87,7 @@ class HourLinePainter extends CustomPainter { startY += dashWidth + dashSpaceWidth; } } else { - canvas.drawLine( - Offset(verticalOffset, 0), - Offset(verticalOffset, size.height), - paint, - ); + canvas.drawLine(Offset(verticalOffset, 0), Offset(verticalOffset, size.height), paint); } } } From eced38a97ed8baf8ca1d9c78edaea85490d11900 Mon Sep 17 00:00:00 2001 From: Gawdat Date: Sun, 17 Sep 2023 11:44:40 +0300 Subject: [PATCH 5/8] fix: formatting --- lib/src/day_view/_internal_day_view_page.dart | 20 ++++++++++---- lib/src/painters.dart | 26 ++++++++++++++----- .../week_view/_internal_week_view_page.dart | 6 +++-- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index 2dee5248..b4d4172a 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -141,7 +141,9 @@ class InternalDayViewPage extends StatelessWidget { width: width, child: Column( children: [ - fullDayEventList.isEmpty ? SizedBox.shrink() : fullDayEventBuilder(fullDayEventList, date), + fullDayEventList.isEmpty + ? SizedBox.shrink() + : fullDayEventBuilder(fullDayEventList, date), Expanded( child: SingleChildScrollView( controller: scrollController, @@ -171,11 +173,13 @@ class InternalDayViewPage 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( @@ -186,7 +190,10 @@ class InternalDayViewPage extends StatelessWidget { minuteSlotSize: minuteSlotSize, ), Align( - alignment: isRtl ? Alignment.centerLeft : Alignment.centerRight, // adjust alignment based on directionality + alignment: isRtl + ? Alignment.centerLeft + : Alignment + .centerRight, // adjust alignment based on directionality child: EventGenerator( height: height, date: date, @@ -196,7 +203,10 @@ class InternalDayViewPage extends StatelessWidget { heightPerMinute: heightPerMinute, eventTileBuilder: eventTileBuilder, scrollNotifier: scrollNotifier, - width: width - timeLineWidth - hourIndicatorSettings.offset - verticalLineOffset, + width: width - + timeLineWidth - + hourIndicatorSettings.offset - + verticalLineOffset, ), ), TimeLine( diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 685595be..410c8d14 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -69,12 +69,14 @@ class HourLinePainter extends CustomPainter { if (lineStyle == LineStyle.dashed) { var startX = offset; while (startX < size.width) { - canvas.drawLine(Offset(startX, dy), Offset(startX + dashWidth, dy), paint); + canvas.drawLine( + Offset(startX, dy), Offset(startX + dashWidth, dy), paint); startX += dashWidth + dashSpaceWidth; if (isRtl && startX > size.width) break; // Stop drawing extra dashes } } else { - canvas.drawLine(Offset(isRtl ? size.width - offset : offset, dy), Offset(isRtl ? 0 : size.width, dy), paint); + canvas.drawLine(Offset(isRtl ? size.width - offset : offset, dy), + Offset(isRtl ? 0 : size.width, dy), paint); } } @@ -83,11 +85,15 @@ class HourLinePainter extends CustomPainter { if (lineStyle == LineStyle.dashed) { var startY = 0.0; while (startY < size.height) { - canvas.drawLine(Offset(verticalOffset + verticalLineOffset, startY), Offset(verticalOffset + verticalLineOffset, startY + dashWidth), paint); + canvas.drawLine( + Offset(verticalOffset + verticalLineOffset, startY), + Offset(verticalOffset + verticalLineOffset, startY + dashWidth), + paint); startY += dashWidth + dashSpaceWidth; } } else { - canvas.drawLine(Offset(verticalOffset, 0), Offset(verticalOffset, size.height), paint); + canvas.drawLine(Offset(verticalOffset, 0), + Offset(verticalOffset, size.height), paint); } } } @@ -147,7 +153,8 @@ class HalfHourLinePainter extends CustomPainter { if (lineStyle == LineStyle.dashed) { var startX = offset; while (startX < size.width) { - canvas.drawLine(Offset(startX, dy), Offset(startX + dashWidth, dy), paint); + canvas.drawLine( + Offset(startX, dy), Offset(startX + dashWidth, dy), paint); startX += dashWidth + dashSpaceWidth; } } else { @@ -202,10 +209,15 @@ class CurrentTimeLinePainter extends CustomPainter { ..strokeWidth = height, ); - if (showBullet) canvas.drawCircle(Offset(offset.dx, offset.dy), bulletRadius, Paint()..color = color); + if (showBullet) + canvas.drawCircle( + Offset(offset.dx, offset.dy), bulletRadius, Paint()..color = color); } @override bool shouldRepaint(covariant CustomPainter oldDelegate) => - oldDelegate is CurrentTimeLinePainter && (color != oldDelegate.color || height != oldDelegate.height || offset != oldDelegate.offset); + oldDelegate is CurrentTimeLinePainter && + (color != oldDelegate.color || + height != oldDelegate.height || + offset != oldDelegate.offset); } diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index ca9ca542..2ab61349 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -192,7 +192,8 @@ class InternalWeekViewPage extends StatelessWidget { ...List.generate( filteredDates.length, (index) { - final fullDayEventList = controller.getFullDayEvent(filteredDates[index]); + final fullDayEventList = + controller.getFullDayEvent(filteredDates[index]); return fullDayEventList.isEmpty ? SizedBox.shrink() : SizedBox( @@ -272,7 +273,8 @@ class InternalWeekViewPage extends StatelessWidget { eventArranger: eventArranger, eventTileBuilder: eventTileBuilder, scrollNotifier: scrollConfiguration, - events: controller.getEventsOnDay(filteredDates[index]), + events: controller + .getEventsOnDay(filteredDates[index]), heightPerMinute: heightPerMinute, ), ], From dafdb0072e7656cd1a893c38193d7d833f54de62 Mon Sep 17 00:00:00 2001 From: Gawdat Date: Sun, 17 Sep 2023 16:45:15 +0300 Subject: [PATCH 6/8] fix: time line indicator --- lib/src/components/_internal_components.dart | 6 ++++- lib/src/day_view/_internal_day_view_page.dart | 5 +++- lib/src/day_view/day_view.dart | 13 +++++++++ lib/src/painters.dart | 27 +++++++++++-------- .../week_view/_internal_week_view_page.dart | 1 + 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/src/components/_internal_components.dart b/lib/src/components/_internal_components.dart index 1c647188..bfedbe01 100644 --- a/lib/src/components/_internal_components.dart +++ b/lib/src/components/_internal_components.dart @@ -35,6 +35,8 @@ class LiveTimeIndicator extends StatefulWidget { /// Defines height occupied by one minute. final double heightPerMinute; + final bool isRtl; + /// Widget to display tile line according to current time. const LiveTimeIndicator( {Key? key, @@ -42,7 +44,8 @@ class LiveTimeIndicator extends StatefulWidget { required this.height, required this.timeLineWidth, required this.liveTimeIndicatorSettings, - required this.heightPerMinute}) + required this.heightPerMinute, + required this.isRtl}) : super(key: key); @override @@ -90,6 +93,7 @@ class _LiveTimeIndicatorState extends State { widget.timeLineWidth + widget.liveTimeIndicatorSettings.offset, _currentDate.getTotalMinutes * widget.heightPerMinute, ), + isRtl: widget.isRtl, ), ); } diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index b4d4172a..e9d1f5e3 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -100,6 +100,8 @@ class InternalDayViewPage extends StatelessWidget { final ScrollController scrollController; + final bool isRtl; + /// Defines a single day page. const InternalDayViewPage({ Key? key, @@ -129,12 +131,12 @@ class InternalDayViewPage extends StatelessWidget { required this.dayDetectorBuilder, required this.showHalfHours, required this.halfHourIndicatorSettings, + required this.isRtl, }) : super(key: key); @override Widget build(BuildContext context) { final fullDayEventList = controller.getFullDayEvent(date); - final isRtl = Directionality.of(context) == TextDirection.rtl; return Container( height: height, @@ -226,6 +228,7 @@ class InternalDayViewPage extends StatelessWidget { height: height, heightPerMinute: heightPerMinute, timeLineWidth: timeLineWidth, + isRtl: isRtl, ), ), ], diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 73ef9bee..1326fca7 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -188,6 +188,14 @@ class DayView extends StatefulWidget { /// By default it will be Duration(hours:0) final Duration startDuration; + /// Indicates if the layout direction is right-to-left (RTL). + /// + /// This value is crucial for correctly drawing the table, especially + /// elements like the vertical line which change position based on + /// the layout direction. Pass this from parent contexts to ensure + /// accurate representation in RTL layouts. + final bool? isRtl; + /// Main widget for day view. const DayView({ Key? key, @@ -228,6 +236,7 @@ class DayView extends StatefulWidget { this.showHalfHours = false, this.halfHourIndicatorSettings, this.startDuration = const Duration(hours: 0), + this.isRtl, }) : assert(timeLineOffset >= 0, "timeLineOffset must be greater than or equal to 0"), assert(width == null || width > 0, @@ -286,9 +295,12 @@ class DayViewState extends State> { final _scrollConfiguration = EventScrollConfiguration(); + late bool isRtl; + @override void initState() { super.initState(); + isRtl = widget.isRtl ?? Directionality.of(context) == TextDirection.rtl; _reloadCallback = _reload; _setDateRange(); @@ -428,6 +440,7 @@ class DayViewState extends State> { showHalfHours: widget.showHalfHours, halfHourIndicatorSettings: _halfHourIndicatorSettings, + isRtl: isRtl, ), ); }, diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 410c8d14..0765ccaf 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -190,28 +190,33 @@ class CurrentTimeLinePainter extends CustomPainter { /// Radius of bullet. final double bulletRadius; + final bool isRtl; + /// Paints a single horizontal line at [offset]. - CurrentTimeLinePainter({ - this.showBullet = true, - required this.color, - required this.height, - required this.offset, - this.bulletRadius = 5, - }); + CurrentTimeLinePainter( + {this.showBullet = true, + required this.color, + required this.height, + required this.offset, + this.bulletRadius = 5, + required this.isRtl}); @override void paint(Canvas canvas, Size size) { + double startX = isRtl ? 0 : size.width; + double endX = isRtl ? size.width - offset.dx : offset.dx; canvas.drawLine( - Offset(offset.dx, offset.dy), - Offset(size.width, offset.dy), + Offset(startX, offset.dy), + Offset(endX, offset.dy), Paint() ..color = color ..strokeWidth = height, ); - if (showBullet) + if (showBullet) { canvas.drawCircle( - Offset(offset.dx, offset.dy), bulletRadius, Paint()..color = color); + Offset(endX, offset.dy), bulletRadius, Paint()..color = color); + } } @override diff --git a/lib/src/week_view/_internal_week_view_page.dart b/lib/src/week_view/_internal_week_view_page.dart index 2ab61349..e9ac0bed 100644 --- a/lib/src/week_view/_internal_week_view_page.dart +++ b/lib/src/week_view/_internal_week_view_page.dart @@ -235,6 +235,7 @@ class InternalWeekViewPage extends StatelessWidget { height: height, heightPerMinute: heightPerMinute, timeLineWidth: timeLineWidth, + isRtl: isRtl, ), Align( alignment: Alignment.centerRight, From 817d1667a4f9d9cb69bd1fffd7edecea13442d6b Mon Sep 17 00:00:00 2001 From: Gawdat Date: Mon, 27 Nov 2023 15:32:25 +0300 Subject: [PATCH 7/8] fix: conflict --- lib/src/day_view/day_view.dart | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 45b48559..e2f6fcd2 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -268,22 +268,23 @@ class DayView extends StatefulWidget { this.emulateVerticalOffsetBy = 0, this.isRtl, }) : assert(!(onHeaderTitleTap != null && dayTitleBuilder != null), - "can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"), + "can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"), assert(timeLineOffset >= 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( - heightPerMinute > 0, "Height per minute must be greater than 0."), - assert( - dayDetectorBuilder == null || onDateLongPress == null, - """If you use [dayPressDetectorBuilder] + ) : 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( + heightPerMinute > 0, "Height per minute must be greater than 0."), + assert( + dayDetectorBuilder == null || onDateLongPress == null, + """If you use [dayPressDetectorBuilder] do not provide [onDateLongPress]""", - ), - super(key: key); + ), + super(key: key); + @override DayViewState createState() => DayViewState(); From 6e0a65787c4fc13558eeabdde37c18d48cb7ac9b Mon Sep 17 00:00:00 2001 From: Gawdat Date: Mon, 27 Nov 2023 15:36:36 +0300 Subject: [PATCH 8/8] fix: conflict --- lib/src/day_view/day_view.dart | 106 +++++++++++---------------------- 1 file changed, 36 insertions(+), 70 deletions(-) diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index e2f6fcd2..b838e1d4 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -267,24 +267,17 @@ class DayView extends StatefulWidget { this.onHeaderTitleTap, this.emulateVerticalOffsetBy = 0, this.isRtl, - }) : assert(!(onHeaderTitleTap != null && dayTitleBuilder != null), - "can't use [onHeaderTitleTap] & [dayTitleBuilder] simultaneously"), - assert(timeLineOffset >= 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( - heightPerMinute > 0, "Height per minute must be greater than 0."), - assert( - dayDetectorBuilder == null || onDateLongPress == null, - """If you use [dayPressDetectorBuilder] + }) : 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."), + assert(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] do not provide [onDateLongPress]""", - ), - super(key: key); - + ), + super(key: key); @override DayViewState createState() => DayViewState(); @@ -347,9 +340,7 @@ class DayViewState extends State> { _regulateCurrentDate(); _calculateHeights(); - _scrollController = ScrollController( - initialScrollOffset: widget.scrollOffset ?? - widget.startDuration.inMinutes * widget.heightPerMinute); + _scrollController = ScrollController(initialScrollOffset: widget.scrollOffset ?? widget.startDuration.inMinutes * widget.heightPerMinute); _pageController = PageController(initialPage: _currentIndex); _eventArranger = widget.eventArranger ?? SideEventArranger(); _assignBuilders(); @@ -359,8 +350,7 @@ class DayViewState extends State> { void didChangeDependencies() { super.didChangeDependencies(); - final newController = widget.controller ?? - CalendarControllerProvider.of(context).controller; + final newController = widget.controller ?? CalendarControllerProvider.of(context).controller; if (newController != _controller) { _controller = newController; @@ -379,8 +369,7 @@ class DayViewState extends State> { void didUpdateWidget(DayView oldWidget) { super.didUpdateWidget(oldWidget); // Update controller. - final newController = widget.controller ?? - CalendarControllerProvider.of(context).controller; + final newController = widget.controller ?? CalendarControllerProvider.of(context).controller; if (newController != _controller) { _controller?.removeListener(_reloadCallback); @@ -389,8 +378,7 @@ class DayViewState extends State> { } // Update date range. - if (widget.minDay != oldWidget.minDay || - widget.maxDay != oldWidget.maxDay) { + if (widget.minDay != oldWidget.minDay || widget.maxDay != oldWidget.maxDay) { _setDateRange(); _regulateCurrentDate(); @@ -438,16 +426,13 @@ class DayViewState extends State> { 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( - key: ValueKey( - _hourHeight.toString() + date.toString()), + key: ValueKey(_hourHeight.toString() + date.toString()), width: _width, - liveTimeIndicatorSettings: - _liveTimeIndicatorSettings, + liveTimeIndicatorSettings: _liveTimeIndicatorSettings, timeLineBuilder: _timeLineBuilder, dayDetectorBuilder: _dayDetectorBuilder, eventTileBuilder: _eventTileBuilder, @@ -458,8 +443,7 @@ class DayViewState extends State> { onTileTap: widget.onEventTap, onDateLongPress: widget.onDateLongPress, onDateTap: widget.onDateTap, - showLiveLine: widget.showLiveTimeLineInAllDays || - date.compareWithoutTime(DateTime.now()), + showLiveLine: widget.showLiveTimeLineInAllDays || date.compareWithoutTime(DateTime.now()), timeLineOffset: widget.timeLineOffset, timeLineWidth: _timeLineWidth, verticalLineOffset: widget.verticalLineOffset, @@ -474,12 +458,9 @@ class DayViewState extends State> { scrollController: _scrollController, showHalfHours: widget.showHalfHours, showQuarterHours: widget.showQuarterHours, - halfHourIndicatorSettings: - _halfHourIndicatorSettings, - quarterHourIndicatorSettings: - _quarterHourIndicatorSettings, - emulateVerticalOffsetBy: - widget.emulateVerticalOffsetBy, + halfHourIndicatorSettings: _halfHourIndicatorSettings, + quarterHourIndicatorSettings: _quarterHourIndicatorSettings, + emulateVerticalOffsetBy: widget.emulateVerticalOffsetBy, isRtl: isRtl, ), ); @@ -526,8 +507,7 @@ class DayViewState extends State> { offset: 5 + widget.verticalLineOffset, ); - assert(_liveTimeIndicatorSettings.height < _hourHeight, - "liveTimeIndicator height must be less than minuteHeight * 60"); + assert(_liveTimeIndicatorSettings.height < _hourHeight, "liveTimeIndicator height must be less than minuteHeight * 60"); _hourIndicatorSettings = widget.hourIndicatorSettings ?? HourIndicatorSettings( @@ -536,8 +516,7 @@ class DayViewState extends State> { offset: 5, ); - assert(_hourIndicatorSettings.height < _hourHeight, - "hourIndicator height must be less than minuteHeight * 60"); + assert(_hourIndicatorSettings.height < _hourHeight, "hourIndicator height must be less than minuteHeight * 60"); _halfHourIndicatorSettings = widget.halfHourIndicatorSettings ?? HourIndicatorSettings( @@ -546,8 +525,7 @@ class DayViewState extends State> { offset: 5, ); - assert(_halfHourIndicatorSettings.height < _hourHeight, - "halfHourIndicator height must be less than minuteHeight * 60"); + assert(_halfHourIndicatorSettings.height < _hourHeight, "halfHourIndicator height must be less than minuteHeight * 60"); _quarterHourIndicatorSettings = widget.quarterHourIndicatorSettings ?? HourIndicatorSettings( @@ -556,8 +534,7 @@ class DayViewState extends State> { offset: 5, ); - assert(_quarterHourIndicatorSettings.height < _hourHeight, - "quarterHourIndicator height must be less than minuteHeight * 60"); + assert(_quarterHourIndicatorSettings.height < _hourHeight, "quarterHourIndicator height must be less than minuteHeight * 60"); } void _calculateHeights() { @@ -569,10 +546,8 @@ class DayViewState extends State> { _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; } @@ -663,8 +638,7 @@ class DayViewState extends State> { /// 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 @@ -720,9 +694,7 @@ class DayViewState extends State> { ); } - Widget _defaultFullDayEventBuilder( - List> events, DateTime date) => - FullDayEventView(events: events, date: date); + Widget _defaultFullDayEventBuilder(List> events, DateTime date) => FullDayEventView(events: events, date: date); HourLinePainter _defaultHourLinePainter( Color lineColor, @@ -747,6 +719,7 @@ class DayViewState extends State> { dashWidth: dashWidth, dashSpaceWidth: dashSpaceWidth, emulateVerticalOffsetBy: emulateVerticalOffsetBy, + isRtl: isRtl, ); } @@ -786,8 +759,7 @@ class DayViewState extends State> { /// 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, ); @@ -805,9 +777,7 @@ class DayViewState extends State> { /// /// Future animateToPage(int page, {Duration? duration, Curve? curve}) => - _pageController.animateToPage(page, - duration: duration ?? widget.pageTransitionDuration, - curve: curve ?? widget.pageTransitionCurve); + _pageController.animateToPage(page, duration: duration ?? widget.pageTransitionDuration, curve: curve ?? widget.pageTransitionCurve); /// Returns current page number. /// @@ -831,8 +801,7 @@ class DayViewState extends State> { /// respectively. /// /// - Future animateToDate(DateTime date, - {Duration? duration, Curve? curve}) async { + Future animateToDate(DateTime date, {Duration? duration, Curve? curve}) async { if (date.isBefore(_minDate) || date.isAfter(_maxDate)) { throw "Invalid date selected."; } @@ -870,8 +839,7 @@ class DayViewState extends State> { /// scroll to event tile. /// /// - Future animateToEvent(CalendarEventData event, - {Duration? duration, Curve? curve}) async { + Future animateToEvent(CalendarEventData event, {Duration? duration, Curve? curve}) async { await animateToDate(event.date, duration: duration, curve: curve); await _scrollConfiguration.setScrollEvent( event: event, @@ -891,8 +859,7 @@ class DayViewState extends State> { // 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); animateTo( offset.toDouble(), duration: duration, @@ -914,6 +881,5 @@ class DayViewState extends State> { } /// 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); }