Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for RTL in HourLine Painters #265

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: time line indicator
  • Loading branch information
Gawdat committed Sep 17, 2023
commit dafdb0072e7656cd1a893c38193d7d833f54de62
6 changes: 5 additions & 1 deletion lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ 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,
required this.width,
required this.height,
required this.timeLineWidth,
required this.liveTimeIndicatorSettings,
required this.heightPerMinute})
required this.heightPerMinute,
required this.isRtl})
: super(key: key);

@override
Expand Down Expand Up @@ -90,6 +93,7 @@ class _LiveTimeIndicatorState extends State<LiveTimeIndicator> {
widget.timeLineWidth + widget.liveTimeIndicatorSettings.offset,
_currentDate.getTotalMinutes * widget.heightPerMinute,
),
isRtl: widget.isRtl,
),
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {

final ScrollController scrollController;

final bool isRtl;

/// Defines a single day page.
const InternalDayViewPage({
Key? key,
Expand Down Expand Up @@ -129,12 +131,12 @@ class InternalDayViewPage<T extends Object?> 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,
Expand Down Expand Up @@ -226,6 +228,7 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
height: height,
heightPerMinute: heightPerMinute,
timeLineWidth: timeLineWidth,
isRtl: isRtl,
),
),
],
Expand Down
13 changes: 13 additions & 0 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ class DayView<T extends Object?> 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,
Expand Down Expand Up @@ -228,6 +236,7 @@ class DayView<T extends Object?> 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,
Expand Down Expand Up @@ -286,9 +295,12 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {

final _scrollConfiguration = EventScrollConfiguration<T>();

late bool isRtl;

@override
void initState() {
super.initState();
isRtl = widget.isRtl ?? Directionality.of(context) == TextDirection.rtl;

_reloadCallback = _reload;
_setDateRange();
Expand Down Expand Up @@ -428,6 +440,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
showHalfHours: widget.showHalfHours,
halfHourIndicatorSettings:
_halfHourIndicatorSettings,
isRtl: isRtl,
),
);
},
Expand Down
27 changes: 16 additions & 11 deletions lib/src/painters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class InternalWeekViewPage<T extends Object?> extends StatelessWidget {
height: height,
heightPerMinute: heightPerMinute,
timeLineWidth: timeLineWidth,
isRtl: isRtl,
),
Align(
alignment: Alignment.centerRight,
Expand Down