Widgets direction does not change to RTL when change localization to Arabic in Flutter
Asked Answered
K

2

8

I have an app and I want to localize it to Arabic using easy_localization package. It changes the language but the direction of the widgets does not change.

void main() {
  runApp(
    EasyLocalization(
      child: MyApp(),
      supportedLocales: [
        Locale('en', 'US'),
        Locale('ku', ''),
        Locale('ar','DZ'),
      ],
      path: 'assets/langs',

    ),
  );
}
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        KuMaterialLocalizations.delegate
      ],
      locale: Locale('ar'),
      title: 'MyApp',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Language(),
    );
  }
}
Khaddar answered 30/4, 2020 at 23:48 Comment(2)
facing same issueCyndy
Also facing same issue, Please help . Thank you.Zither
A
-1

In the Home Page set the Locale Property with context.locale.languageCode ,localizationsDelegates and supportedLocales aswell

 return MaterialApp(
    localizationsDelegates: context.localizationDelegates,
    supportedLocales: [Locale('en', 'US'), Locale('ar', 'SA')],
    locale: Locale(context.locale.languageCode),
    home: LoginStatePage());

}

if you want to override the default language, in Main.Dart

you can set the property startLocale of EasyLocalization

runApp(
EasyLocalization(
    supportedLocales: [Locale('en', 'US'), Locale('ar', 'SA')],
    path: 'assets/translations',
    assetLoader: CodegenLoader(),
    saveLocale: true,
    startLocale: Locale('ar', 'SA'),
    child: MyApp()),

);

Attaboy answered 9/10, 2020 at 17:55 Comment(0)
N
-1

You can use this answer HERE.

add key to material app like key: ValueKey<Locale>(context.locale), or wrap Material app with AnimatedSwitcher widget with key above also to reflect without load entire app.

Naman answered 8/3, 2021 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.