Search code examples
flutterdartflutter-appbar

Change the text direction in the AppBar from going LTR to RTL flutter


I have an application that I'm building and in it, I have an AppBar. My text is in Arabic and I want to make the text place change from LTR (left-to-right) to RTL (right-to-left)

Here is a screenshot of the AppBar

enter image description here

And this is the code for my AppBar

class MyAppBar extends StatelessWidget with PreferredSizeWidget {

  @override
  Size get preferredSize => Size.fromHeight(kToolBarHeight);

  @override
  Widget build(BuildContext context) {
    return AppBar(
      title: Text(
        kAppBarTitleFirst,
      ),
    );
  }
}

So the question is:- How can I get the text عنوان التطبيق to be in the place of the red that I marked (see screenshot above)


Solution

  • Use textDirection property of Text widget.

    class MyAppBar extends StatelessWidget with PreferredSizeWidget {
    
      @override
      Size get preferredSize => Size.fromHeight(kToolBarHeight);
    
      @override
      Widget build(BuildContext context) {
        return AppBar(
          title: Text(
            kAppBarTitleFirst,
            textDirection:TextDirection.rtl  // ← add this line
          ),
        ); 
      }
    }