Skip to main content

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.
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

Layout Direction and Language

Layout direction and language are two separate settings: 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:
layoutDirection accepts three values: 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:
See Localize 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.
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:
Leave it null (or pass auto) to inherit the direction from the component around it, or from the global setting. These components take layoutDirection:
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:
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

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:
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. 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.

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

Localize

Set the UI Kit’s language and translations

Methods

UIKitSettings and CometChatUIKit reference

Customization

Custom views, templates and styles

Troubleshooting

Common RTL questions