الانتقال إلى المحتوى
تطبيقات الموبايلFlutter· 7 دقائق للقراءة

Arabic Support Is More Than Translation: RTL Layouts Done Right in Flutter

Arabic strings don't flip a layout. The locale sets the direction, and every hard-coded left or right is a bug waiting for it.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Flutter 3.x
محتويات المقال

The Arabic release passed translation review: every string comes from the ARB files and reads well. On the first Arabic test build, the screens still run left to right. After someone adds Locale('ar') to the app, most of it flips, but the order list doesn't look right. The 16-pixel gap now sits next to the arrow instead of where the Arabic text starts, the titles hug the wrong edge, the discount badge is stuck in the top-left corner, and every row's arrow points back into the text.

The common misconception

The belief: supporting Arabic means translating the strings. Flutter handles RTL, so once the text is Arabic, the layout will sort itself out.

It's half right, and that's why it's convincing. Flutter really does a lot of the : a Row lays out its children from right to left, ListTile and AppBar swap their leading and trailing sides, and the default text alignment follows the direction. A demo screen built only from those widgets flips perfectly. But it only flips when the app knows its locale is RTL, and only the parts written in terms of "start" and "end". Real apps are full of left: 16.

What actually happens

Direction is a value in the tree, set by the locale

Every widget that cares about direction reads it from Directionality, an that "determines the ambient directionality of text and text-direction-sensitive render objects". You rarely add one yourself: MaterialApp builds a Localizations widget, and that widget inserts the Directionality for the current locale.

The catch is in Flutter's internationalization docs: "By default, Flutter only provides US English localizations." It's GlobalWidgetsLocalizations.delegate, from the flutter_localizations package, that "defines the default text direction, either left-to-right or right-to-left". And the app only follows the device's locale if its language is in supportedLocales. Your strings can come from anywhere; the direction doesn't come from them.

We checked this in widget tests. A MaterialApp showing Arabic text with no locale setup read TextDirection.ltr. Setting locale: Locale('ar') without the delegates still gave ltr, plus a warning that the locale "is not supported by all of its localization delegates". Only with the delegates and Locale('ar') in supportedLocales did it become rtl.

Dart main.dart
void main() {  runApp(const MaterialApp(    // Includes GlobalWidgetsLocalizations, which marks Arabic as RTL    localizationsDelegates: GlobalMaterialLocalizations.delegates,    supportedLocales: [Locale('ar'), Locale('en')],    home: OrdersScreen(),  ));}

Physical values don't flip

Once the direction is RTL, Flutter flips what you described relatively and keeps what you described physically. The EdgeInsets docs say its left and right values "are not affected by the TextDirection" and point you to EdgeInsetsDirectional, whose start is "the side from which the user will start reading text". The same split runs through the framework: Alignment and AlignmentDirectional, Positioned and PositionedDirectional, TextAlign.left and TextAlign.start.

Icons flip only if they're marked

An Icon mirrors in RTL only when its IconData has matchTextDirection set to true. In Flutter's Icons class, arrow_back and chevron_right have it; keyboard_arrow_right, which looks almost the same, doesn't. That flag matches Apple's guidance: "Flip an interface icon that shows forward or backward motion", so "a back button must point to the right" in RTL. But "Don't flip logos or universal signs and marks", a clock stays a clock, and you should "avoid flipping images like photographs".

Text follows its own language

Two more rules from Apple are easy to miss. "Don't reverse the order of numerals in a specific number": an order number reads the same in both directions. And "Align a paragraph based on its language, not on the current context", where a paragraph means three or more lines. An English review shown in the Arabic UI is hard to read when it's aligned to the right. TextAlign.start follows the ambient direction, so for user-generated text, pass a textDirection that matches the content. The intl package's Bidi.detectRtlDirectionality estimates it: in a quick test, it returned false for "Great food, slow delivery" and true for an Arabic sentence.

Fixing the order row

Dart order_row.dart
class OrderRow extends StatelessWidget {  const OrderRow({super.key, required this.title});  final String title;  @override  Widget build(BuildContext context) => Padding(        // Physical sides: they stay put when the layout flips        padding: const EdgeInsets.only(left: 16, right: 8),        child: Row(children: [          Expanded(child: Text(title, textAlign: TextAlign.left)),          const Icon(Icons.keyboard_arrow_right), // never mirrored        ]),      );}

In a widget test on an 800-pixel-wide screen set to RTL, the Row flipped both versions: the icon moved to the left end. But the wrong row kept 16 pixels on the left, next to the icon, and only 8 on the right, where Arabic text starts. Its title hugged the left edge of its space, and the arrow still pointed right, back into the text. The right row had 16 pixels on the right, a right-aligned title and a mirrored chevron. In LTR, the two rows were pixel-identical, which is why this bug survives every review done in English.

Physical (never flips)Directional (follows the locale)
EdgeInsets.only(left: 16)EdgeInsetsDirectional.only(start: 16)
Alignment.centerLeftAlignmentDirectional.centerStart
Positioned(left: 0)PositionedDirectional(start: 0)
TextAlign.leftTextAlign.start
BorderRadius.only(topLeft: ...)BorderRadiusDirectional.only(topStart: ...)

How to apply it in your project

  1. Make the locale RTL-aware firstAdd flutter_localizations from the SDK, pass GlobalMaterialLocalizations.delegates and list Locale('ar') in supportedLocales. Check Directionality.of(context) on a real screen before touching any layout.
  2. Search for physical valuesLook for EdgeInsets.only(left, fromLTRB, Alignment.centerLeft, Positioned(left, TextAlign.left and BorderRadius.only(topLeft. Convert each one to its directional version unless the direction is meant to be physical.
  3. Audit your iconsArrows that mean back, forward or "next" must mirror: use icons with matchTextDirection, or set it on your own IconData. Leave logos, checkmarks, clocks and photos alone.
  4. Mind custom drawing and motionA CustomPainter or a slide animation with an Offset works in physical coordinates. Read Directionality.of(context) and flip the math yourself where it carries meaning.
  5. Test both directionsRun your widget and golden tests in LTR and RTL, and do a manual pass with real Arabic text, since its length rarely matches the English.

Key takeaways

  • Direction comes from the locale through Directionality, not from the language of your strings.
  • Without flutter_localizations and Locale('ar') in supportedLocales, an Arabic app stays LTR.
  • Directional APIs (start, end, EdgeInsetsDirectional) flip; physical ones (left, right) never do.
  • Only icons with matchTextDirection mirror; numbers, logos and photos shouldn't.
  • Test every screen in RTL, because an LTR review can't see these bugs.

📚 المصادر

  1. Internationalizing Flutter apps — Flutter docs
  2. Directionality class — Flutter API
  3. EdgeInsetsDirectional class — Flutter API
  4. IconData.matchTextDirection — Flutter API
  5. Right to left — Apple Human Interface Guidelines

التعليقات (0)