Skip to content

Commit 2aea151

Browse files
author
Shubham Jitiya
committed
feat: Fixes issue #412: ✨ Add support for RTL directionality
1 parent 2759702 commit 2aea151

24 files changed

+709
-368
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Adds clear method to `EventController`.
44
- Adds `onEventTapDetails`, `onEventDoubleTapDetails` & `onEventLongTapDetails` gesture recognizers to get tap details. [#390](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/390)
5+
- Adds support of directionality. [#412](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/412)
56

67
# [1.4.0 - 7 Jan 2025](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.4.0)
78

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,30 @@ WeekView(
357357
],
358358
);
359359
```
360-
361360
Above code will create `WeekView` with only five days, from monday to friday.
362361

362+
### Support for RTL
363+
Wrap your widget with `Directionality` widget and use `textDirection` to give RTL or LTR direction.
364+
365+
```dart
366+
Directionality(
367+
textDirection: TextDirection.rtl,
368+
child: ResponsiveWidget(
369+
webWidget: WebHomePage(
370+
selectedView: CalendarView.week,
371+
),
372+
mobileWidget: Scaffold(
373+
floatingActionButton: FloatingActionButton(
374+
child: Icon(Icons.add),
375+
elevation: 8,
376+
onPressed: () => context.pushRoute(CreateEventPage()),
377+
),
378+
body: WeekViewWidget(),
379+
),
380+
),
381+
);
382+
```
383+
363384
## Main Contributors
364385

365386
<table>

example/lib/constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class AppConstants {
66
AppConstants._();
77

88
static final List<String> weekTitles = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
9+
static final ltr = '\u202A'; // Use this to force text direction to LTR
910

1011
static OutlineInputBorder inputBorder = OutlineInputBorder(
1112
borderRadius: BorderRadius.circular(7),

example/lib/pages/create_event_page.dart

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,60 @@ import '../extension.dart';
66
import '../widgets/add_event_form.dart';
77

88
class CreateEventPage extends StatelessWidget {
9-
const CreateEventPage({super.key, this.event});
9+
const CreateEventPage({
10+
super.key,
11+
this.event,
12+
this.directionality = TextDirection.ltr,
13+
});
1014

1115
final CalendarEventData? event;
16+
final TextDirection directionality;
1217

1318
@override
1419
Widget build(BuildContext context) {
15-
return Scaffold(
16-
appBar: AppBar(
17-
elevation: 0,
18-
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
19-
centerTitle: false,
20-
leading: IconButton(
21-
onPressed: context.pop,
22-
icon: Icon(
23-
Icons.arrow_back,
24-
color: AppColors.black,
20+
return Directionality(
21+
textDirection: directionality,
22+
child: Scaffold(
23+
appBar: AppBar(
24+
elevation: 0,
25+
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
26+
centerTitle: false,
27+
leading: IconButton(
28+
onPressed: context.pop,
29+
icon: Icon(
30+
Icons.arrow_back,
31+
color: AppColors.black,
32+
),
2533
),
26-
),
27-
title: Text(
28-
event == null ? "Create New Event" : "Update Event",
29-
style: TextStyle(
30-
color: AppColors.black,
31-
fontSize: 20.0,
32-
fontWeight: FontWeight.bold,
34+
title: Text(
35+
event == null ? "Create New Event" : "Update Event",
36+
style: TextStyle(
37+
color: AppColors.black,
38+
fontSize: 20.0,
39+
fontWeight: FontWeight.bold,
40+
),
3341
),
3442
),
35-
),
36-
body: SingleChildScrollView(
37-
physics: ClampingScrollPhysics(),
38-
child: Padding(
39-
padding: EdgeInsets.all(20.0),
40-
child: AddOrEditEventForm(
41-
onEventAdd: (newEvent) {
42-
if (this.event != null) {
43-
CalendarControllerProvider.of(context)
44-
.controller
45-
.update(this.event!, newEvent);
46-
} else {
47-
CalendarControllerProvider.of(context).controller.add(newEvent);
48-
}
43+
body: SingleChildScrollView(
44+
physics: ClampingScrollPhysics(),
45+
child: Padding(
46+
padding: EdgeInsets.all(20.0),
47+
child: AddOrEditEventForm(
48+
onEventAdd: (newEvent) {
49+
if (this.event != null) {
50+
CalendarControllerProvider.of(context)
51+
.controller
52+
.update(this.event!, newEvent);
53+
} else {
54+
CalendarControllerProvider.of(context)
55+
.controller
56+
.add(newEvent);
57+
}
4958

50-
context.pop(true);
51-
},
52-
event: event,
59+
context.pop(true);
60+
},
61+
event: event,
62+
),
5363
),
5464
),
5565
),

example/lib/pages/day_view_page.dart

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import 'create_event_page.dart';
88
import 'web/web_home_page.dart';
99

1010
class DayViewPageDemo extends StatefulWidget {
11-
const DayViewPageDemo({super.key});
11+
const DayViewPageDemo({
12+
super.key,
13+
this.directionality = TextDirection.ltr,
14+
});
15+
16+
final TextDirection directionality;
1217

1318
@override
1419
_DayViewPageDemoState createState() => _DayViewPageDemoState();
@@ -17,17 +22,24 @@ class DayViewPageDemo extends StatefulWidget {
1722
class _DayViewPageDemoState extends State<DayViewPageDemo> {
1823
@override
1924
Widget build(BuildContext context) {
20-
return ResponsiveWidget(
21-
webWidget: WebHomePage(
22-
selectedView: CalendarView.day,
23-
),
24-
mobileWidget: Scaffold(
25-
floatingActionButton: FloatingActionButton(
26-
child: Icon(Icons.add),
27-
elevation: 8,
28-
onPressed: () => context.pushRoute(CreateEventPage()),
25+
return Directionality(
26+
textDirection: widget.directionality,
27+
child: ResponsiveWidget(
28+
webWidget: WebHomePage(
29+
selectedView: CalendarView.day,
30+
),
31+
mobileWidget: Scaffold(
32+
floatingActionButton: FloatingActionButton(
33+
child: Icon(Icons.add),
34+
elevation: 8,
35+
onPressed: () => context.pushRoute(
36+
CreateEventPage(
37+
directionality: widget.directionality,
38+
),
39+
),
40+
),
41+
body: DayViewWidget(),
2942
),
30-
body: DayViewWidget(),
3143
),
3244
);
3345
}

0 commit comments

Comments
 (0)