Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change direction of dialog texts to RTL in Flutter?

I have the following codes in my login page:

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Directionality(
        textDirection: TextDirection.rtl,
        child: . . .
        .
        .
        .
         showDialog(
             context: context,
             barrierDismissible: false,
             builder: (context) => AlertDialog(
             title: const Text('خطا'),
             content: Text('جهت تست'),
             actions: [
                TextButton(
                onPressed: () {
                       Navigator.pop(context);
                       },
                       child: const Text("تایید"))
                   ],
                ),
            );
}

When I run the code, everything is in RTL mode but the dialog is in LTR mode. How can I make it RTL?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

wrap the widget returned in the showDialog with a Directionality:

showDialog(
             context: context,
             barrierDismissible: false,
             builder: (context) => Directionality(textDirection: /* your text direction*/, child: AlertDialog(
             title: const Text('خطا'),
             content: Text('جهت تست'),
             actions: [
                TextButton(
                onPressed: () {
                       Navigator.pop(context);
                       },
                       child: const Text("تایید"))
                   ],
                ),
            ),);

With changing /* your text direction*/ with your desired direction.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading