There are too many languages in my application. My application works perfectly when I select a language that should have rtl direction (for example: Arabic, Iranian). It changes all widgets and fonts from ltr to rtl, when i select the language and restart the app, the language works correctly but the layout of the widgets is still ltr. How to check the directions of widgets at the beginning and change if necessary?
Asked
Active
Viewed 208 times
0
-
https://stackoverflow.com/questions/31904627/android-change-entire-app-layout-directions-programmatically – Akash Pal Feb 17 '21 at 07:37
-
make sure you set the rtl config in onStart – Akash Pal Feb 17 '21 at 07:38
2 Answers
1
You can use your MaterialApp builder for this:
return MaterialApp(
// rest of your application,
builder: (context, child) => Directionality(
textDirection: TextDirection.rtl,
child: child,
),
)
Ref: https://pub.dev/documentation/simple_flutter_i18n/latest/

Thierry
- 7,775
- 2
- 15
- 33
-
This code helps me to solve my problem, thank you but i want to ask one more question, how can i check if language direction is RTL ? Actually how to check which language selected? – Ergün Yunus Cengiz Feb 17 '21 at 08:38
-
The reference I provided will get into more details about how to do this with i18n. You could also use a Locale Provider. – Thierry Feb 17 '21 at 09:14
0
In addition to the solution of a user named Thierry, whose answer I accepted as correct, I ran the following code and got what I wanted.
The code:
var data = EasyLocalizationProvider.of(context).data;
return EasyLocalizationProvider(
data: data,
//The important part is below:
child: MaterialApp(
builder: (context, child) => Directionality(
textDirection: data.savedLocale == Locale('ar', '')
? TextDirection.rtl
: data.savedLocale == Locale('fa', '')
? TextDirection.rtl
: TextDirection.ltr,
child: child,
),
My solution is: "data.savedLocale" --> The savedLocale function is in easy_localization_provider package that i use. I checked language code if 'ar' or 'fa' and by result execute the text direction.

Ergün Yunus Cengiz
- 311
- 3
- 15