> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# RTL Support

> Show CometChat Flutter UI Kit components right to left for Arabic and other RTL languages, globally or per component, with layoutDirection.

> [accordion] AI Integration Quick Reference
>
> | Field | Value |
> | - | - |
> | Package | `cometchat_chat_uikit` |
> | Requires | UI Kit 6.5.0 or later |
> | Default | **Follows the app.** Without the `layoutDirection` setting, `CometChatLayoutDirection.auto` uses the app's direction, so an app with an Arabic locale is RTL with no extra code |
> | Enable | `UIKitSettingsBuilder()..layoutDirection = CometChatLayoutDirection.rtl`, then `CometChatUIKit.init()` |
> | Import | `import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';` |
> | Purpose | Show UI Kit components right to left (RTL) or left to right (LTR), for the whole kit or for one component. |
> | Runtime change | `CometChatUIKit.setLayoutDirection(...)`, then reopen the UI Kit screens |
> | Per component | `layoutDirection` parameter on every screen component |
> | Values | `CometChatLayoutDirection.auto` (default) · `.ltr` · `.rtl` |
> | Related | [Localize](https://www.cometchat.com/docs/ui-kit/flutter/localize.md) · [Offline Support](https://www.cometchat.com/docs/ui-kit/flutter/offline-support.md) · [Methods](https://www.cometchat.com/docs/ui-kit/flutter/methods.md) · [Customization Overview](https://www.cometchat.com/docs/ui-kit/flutter/customization-overview.md) |

## Overview

Languages such as Arabic are read right to left. In an RTL layout, the UI Kit mirrors its components: avatars, names, buttons, message bubbles, menus and sheets swap sides, and arrows point the other way.

Mirroring the layout doesn't mean flipping the content. The UI Kit keeps every piece of content readable:

* Each message reads in its own direction, so an English message in an Arabic chat still reads left to right.
* Names, mentions and numbers keep their order inside the text around them.
* Audio and video players and code blocks stay left to right, as they do in every RTL app.

> [!NOTE]
>
> RTL support is available from Flutter UI Kit **6.5.0**. By default the UI Kit follows the app's direction, so an app that doesn't set `layoutDirection` keeps its current direction.

## Requirements

| Requirement | Version |
| - | - |
| `cometchat_chat_uikit` | 6.5.0 or later |

## Layout Direction and Language

Layout direction and language are two separate settings:

| Setting | Decides | Set with |
| - | - | - |
| Layout direction | Which side things sit on | `layoutDirection` |
| Language | Which strings are shown | The app's locale (see [Localize](https://www.cometchat.com/docs/ui-kit/flutter/localize.md)) |

By default the UI Kit follows the app's direction, and `MaterialApp` makes an app RTL when its locale is an RTL language. You can also set them apart, for example an English app laid out RTL, or an Arabic app kept LTR.

## Enable RTL Support

Add the `layoutDirection` field to the `UIKitSettings` you pass to `CometChatUIKit.init()`. It gives every UI Kit component a fixed direction, whatever the app's direction, and your own screens are not affected:

> [tab] Dart
>
> ```dart theme={null}
> UIKitSettings uiKitSettings = (UIKitSettingsBuilder()
>   ..appId = "your_appID"
>   ..region = "your_region"
>   ..authKey = "your_authKey"
>   ..layoutDirection = CometChatLayoutDirection.rtl
> ).build();
>
> CometChatUIKit.init(uiKitSettings: uiKitSettings);
> ```

`layoutDirection` accepts three values:

| Value | Result |
| - | - |
| `CometChatLayoutDirection.auto` | Follows the app's direction. This is the default, so apps that don't set it keep their current direction. |
| `CometChatLayoutDirection.ltr` | Every UI Kit component is left to right. |
| `CometChatLayoutDirection.rtl` | Every UI Kit component is right to left. |

If you leave `layoutDirection` out, the UI Kit uses `auto` and follows the app's direction.

### Follow the app's language (default)

With the default value, `CometChatLayoutDirection.auto`, the UI Kit uses the direction the app is already in. `MaterialApp` makes the app RTL when its locale is an RTL language, so setting an Arabic locale is all you need:

> [tab] Dart
>
> ```dart theme={null}
> MaterialApp(
>   locale: const Locale('ar'),
>   supportedLocales: CometChatLocalize.supportedLocales,
>   localizationsDelegates: CometChatLocalize.localizationsDelegates,
>   home: const YourHomeScreen(),
> )
> ```

See [Localize](https://www.cometchat.com/docs/ui-kit/flutter/localize.md) for the full locale setup.

### Change it at runtime

Use `CometChatUIKit.setLayoutDirection` to change the direction while the app is running, for example from a settings screen. Read the current value with `CometChatUIKit.layoutDirection`.

> [tab] Dart
>
> ```dart theme={null}
> CometChatUIKit.setLayoutDirection(CometChatLayoutDirection.rtl);
>
> final current = CometChatUIKit.layoutDirection; // CometChatLayoutDirection.rtl
> ```

> [!NOTE]
>
> The new direction applies to screens opened after the change. A screen that is already open keeps its direction until it is reopened. `init()` sets the direction again from `UIKitSettings.layoutDirection`, so call `setLayoutDirection` after `init()`.

## Set It Per Component

Every screen component takes a `layoutDirection` parameter. It overrides the global setting for that component and everything inside it, including the dialogs, sheets, menus and toasts it opens:

> [tab] Dart
>
> ```dart theme={null}
> // The whole kit is RTL, but this list stays LTR.
> CometChatConversations(
>   layoutDirection: CometChatLayoutDirection.ltr,
> )
> ```

Leave it `null` (or pass `auto`) to inherit the direction from the component around it, or from the global setting.

These components take `layoutDirection`:

| Chat | Calls | Messages |
| - | - | - |
| [Conversations](https://www.cometchat.com/docs/ui-kit/flutter/conversations.md) | [Call Buttons](https://www.cometchat.com/docs/ui-kit/flutter/call-buttons.md) | [Message Header](https://www.cometchat.com/docs/ui-kit/flutter/message-header.md) |
| [Users](https://www.cometchat.com/docs/ui-kit/flutter/users.md) | [Call Logs](https://www.cometchat.com/docs/ui-kit/flutter/call-logs.md) | [Message List](https://www.cometchat.com/docs/ui-kit/flutter/message-list.md) |
| [Groups](https://www.cometchat.com/docs/ui-kit/flutter/groups.md) | [Outgoing Call](https://www.cometchat.com/docs/ui-kit/flutter/outgoing-call.md) | [Message Composer](https://www.cometchat.com/docs/ui-kit/flutter/message-composer.md) |
| [Group Members](https://www.cometchat.com/docs/ui-kit/flutter/group-members.md) | `CometChatOngoingCall` | [Threaded Messages Header](https://www.cometchat.com/docs/ui-kit/flutter/threaded-messages-header.md) |
| [Search](https://www.cometchat.com/docs/ui-kit/flutter/search.md) | | `CometChatMessageInformation` |
| [Notification Feed](https://www.cometchat.com/docs/ui-kit/flutter/notification-feed.md) | | [Pinned Messages](https://www.cometchat.com/docs/ui-kit/flutter/pinned-messages.md) |
| `CometChatAIAssistantChatHistory` | | [Saved Messages](https://www.cometchat.com/docs/ui-kit/flutter/saved-messages.md) |

> [!NOTE]
>
> On Android and iOS, incoming calls ring on the system call screen, which follows the phone's language. The deprecated `CometChatIncomingCall` screen (web only) has no `layoutDirection`; it follows the app's direction.

## Which Setting Wins

When settings disagree, the first rule that gives a direction wins:

1. Audio and video players are always left to right.
2. The component's own `layoutDirection`, when it is `ltr` or `rtl`.
3. The nearest UI Kit component around it that has its own `layoutDirection`.
4. The global setting, when it is `ltr` or `rtl`.
5. The app's own direction, or left to right when there is none.

So wrapping a component in Flutter's `Directionality` changes it only while the global setting is `auto`. To force one component's direction, use its `layoutDirection` parameter.

## App Screens Outside the UI Kit

The UI Kit never changes your app's direction. With a global `ltr` or `rtl`, the UI Kit's components follow it but your own screens stay as they are. To give your own screens the same direction, set the direction in `MaterialApp.builder`:

> [tab] Dart
>
> ```dart theme={null}
> MaterialApp(
>   locale: locale,
>   // ...
>   builder: (context, child) {
>     final direction = CometChatUIKit.layoutDirection.toTextDirection();
>     if (direction == null) return child!; // auto: the locale decides
>     return Directionality(textDirection: direction, child: child!);
>   },
> )
> ```

With `auto` the locale decides for both your screens and the UI Kit, so nothing extra is needed.

## What Changes in RTL

### Layout

Everything that has a side moves to the other one: avatars, titles, subtitles, timestamps, unread badges, receipts, buttons, the composer's actions, message bubbles, menus, sheets, swipe actions and list indicators. Sent messages sit on the left and received messages on the right.

### Icons

| Icon | In RTL |
| - | - |
| Arrows that point along the reading direction: back, forward, send, reply, reply in thread, and call-direction arrows (incoming, outgoing, missed) | Flip on every platform |
| Video camera, copy, chat and sticker | Flip on Android and web; stay as drawn on iOS and macOS (Apple's guidelines) and on Windows and Linux |
| Everything else: phone handset, microphone, attach, emoji, close, search, receipt ticks, pin, media controls, file types, logos | Stay as drawn |

In an LTR layout every icon is Flutter's own, for example `Icons.videocam`; the direction-following copies are used only in RTL. Icons you pass into the UI Kit are drawn as you give them. For an arrow that should flip, use an icon with `matchTextDirection: true` (Material's arrow icons already have it).

### What doesn't mirror

* **Audio and video players**, including voice notes and the recorder: playback controls and progress bars stay left to right in every language.
* **Code blocks in AI assistant replies** stay left to right.

### Message text

* **Each line reads in its own direction.** The first letter of a line decides it: a line that starts with an English letter reads left to right, one that starts with an Arabic letter reads right to left. A line with no letters (only emoji or numbers) follows the bubble.
* **Names and mentions keep their place.** A user's name can't scramble the sentence around it, and a mention always reads `@name`, whatever the language of the name or the line. To do this, in an RTL layout or around right-to-left text, the UI Kit wraps names, mentions and dates in its own sentences in invisible Unicode isolates (U+2066 to U+2069). Text the UI Kit builds for you, such as a conversation's last-message preview, can contain them. An LTR layout with left-to-right text gets the same strings as before 6.5.0.
* **Numbers and dates.** When the UI Kit's language is Arabic, dates, times and counts it formats use Arabic digits (٠١٢٣٤٥٦٧٨٩). An English app set to RTL keeps English dates and Western digits. Text you supply yourself, for example from a date formatter callback, is shown as given. Text the UI Kit doesn't format keeps its own digits, such as a file's extension (MP3) or a keycap emoji.
* **Text the UI Kit writes** keeps its language's order: in an English app set to RTL, "Delete this chat?" still ends with its question mark.

### Message composer

* The text follows the language you type, line by line: a line that starts with an English letter reads from the left, one that starts with an Arabic letter from the right. The field takes the direction of the line the cursor is on.
* On iOS, the keyboard's language decides the direction while you type, so with an Arabic keyboard an empty line starts at the right.

## Custom Views in RTL

Views you pass into the UI Kit (view slots, custom message templates, custom bubbles) are placed inside the component's direction, so they read `Directionality.of(context)` like any Flutter widget. Use direction-aware values so they mirror with the rest of the UI Kit:

| Instead of | Use |
| - | - |
| `EdgeInsets.only(left: 8)` | `EdgeInsetsDirectional.only(start: 8)` |
| `Alignment.centerLeft` | `AlignmentDirectional.centerStart` |
| `BorderRadius.only(topLeft: ...)` | `BorderRadiusDirectional.only(topStart: ...)` |
| `Positioned(left: 0)` | `PositionedDirectional(start: 0)` |
| `TextAlign.left` | `TextAlign.start` |

> [tab] Dart
>
> ```dart theme={null}
> CometChatConversations(
>   subtitleView: (context, conversation) => Padding(
>     // Mirrors with the list: 8 px on the left in LTR, on the right in RTL.
>     padding: const EdgeInsetsDirectional.only(start: 8),
>     child: Text(
>       conversation.lastMessage?.sender?.name ?? '',
>       textAlign: TextAlign.start,
>     ),
>   ),
> )
> ```

`Row`, `ListTile` and other Flutter layouts already follow the direction.

## Languages

The UI Kit ships Arabic translations. For another RTL language, such as Hebrew, Persian or Urdu, add the language as described in [Adding New Language Support](https://www.cometchat.com/docs/ui-kit/flutter/localize.md#adding-new-language-support). Once its locale is set, `auto` lays the UI Kit out right to left.

## With RTL Support Left at Default

If you don't set `layoutDirection`, the UI Kit uses `auto`: it follows the app's direction, as an app does with any RTL language. An app that is already RTL needs no extra code, and an LTR app stays LTR. Upgrading to 6.5.0 still changes a few things for every app, whatever its direction:

* **Message text reads in its own direction**, and names, mentions and numbers keep their order inside the text around them.
* **The new-messages divider** is a single line with a "New" label at its end.
* **The Notification Feed's** default title and empty state are translated, and the title uses heading 1, as the other screens do.
* **On iOS, the message action menu's icons** sit next to their labels, at the start of each row, as on Android.
* **In Create Poll**, each option's drag handle sits at the start of its row. Long-press on a row still reorders on Android and iOS.
* **Custom translations**: a class that `implements Translations` must add 3 new strings. See [Localize](https://www.cometchat.com/docs/ui-kit/flutter/localize.md).

## Limitations

* A direction changed at runtime reaches only screens opened after the change, so reopen the UI Kit screens.
* The call itself is drawn by the Calls SDK: its video and controls don't follow `layoutDirection`.
* On Android and iOS, incoming calls ring on the system call screen, which follows the phone's language.
* Icons you pass into the UI Kit are drawn as you give them. For an arrow that should flip, use an icon with `matchTextDirection: true`.
* Your own screens keep the app's direction. The UI Kit never changes it.

## Next Steps

> [card] [Localize](https://www.cometchat.com/docs/ui-kit/flutter/localize.md)
>
> Set the UI Kit's language and translations

> [card] [Methods](https://www.cometchat.com/docs/ui-kit/flutter/methods.md)
>
> UIKitSettings and CometChatUIKit reference

> [card] [Customization](https://www.cometchat.com/docs/ui-kit/flutter/customization-overview.md)
>
> Custom views, templates and styles

> [card] [Troubleshooting](https://www.cometchat.com/docs/ui-kit/flutter/troubleshooting.md)
>
> Common RTL questions


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.