Getx: RTL directionality support

Created on 12 Sep 2020  Â·  12Comments  Â·  Source: jonataslaw/getx

Wonderful package!
Is there a way to change layout direction for RTL languages when using GetX translations?

Waiting for customer response bug documentation

All 12 comments

Thanks for noticing that @smokelaboratory !
I didn't try the internationalisation capabilities of GetXâ„¢ until now.
I just pushed a fix to refresh the UI when you Get.changeLocale(), and included in the docs and README.
Please, give it a try when it gets merged, and let me know if the issue is solved.

@roipeker

I have same issue, and I try what you included in README, but still have issue.
layout does not update on changing locale, but update after after hot reload.

  Widget build(BuildContext context) {
    return StoreProvider<AppState>(
      store: store,
      child: AppThemeProvider(
        child: (themeContext) => GetMaterialApp(
          title: Strings.appName,
          debugShowCheckedModeBanner: false,
          localizationsDelegates: [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          translations: Translation(),
          locale: Locale('fa', 'IR'),
          fallbackLocale: Locale('en', 'US'),
          supportedLocales: [Locale('fa', 'IR'), Locale('en', 'US')],
          popGesture: true,
          theme: ThemeProvider.themeOf(themeContext).data,
          home: InitialApp(),
        ),
      ),
    );
  }

@Hamidrezana

I think the change is not yet merged. It is under review.
Here is the PR for it (https://github.com/jonataslaw/getx/pull/601)

@smokelaboratory tnx.

wonderful approach

Hy here is the temporary fix To Change Language using GetX utils(RTL and LTR)

  1. import flutter_localizations SDK
  2. Make your MyApp base Widget to stateful
  3. Write these lines in MyApp base widget
static void setLocale(BuildContext context,Locale locale){
  final _MyAppState state=context.findAncestorStateOfType<_MyAppState>();
  state.setLocale(locale);
  1. And these Lines in _MyAppState Widget
void setLocale(Locale locale){
  setState(() {
    _locale=locale;
  });
}
Locale _locale;
  1. Add these lines in GetMaterialApp
locale: _locale??_setLanguage(),
localeResolutionCallback: (deviceLocale,supportedLocale){
  for(final locale in supportedLocale){
    if(locale.languageCode==deviceLocale.languageCode&&locale.countryCode==deviceLocale.countryCode){
      return deviceLocale;
    }
  }
  return supportedLocale.first;
},
localizationsDelegates: [
  GlobalCupertinoLocalizations.delegate,
  GlobalMaterialLocalizations.delegate,
  GlobalWidgetsLocalizations.delegate,
],
supportedLocales: <Locale>[Locale('en', 'UK'),  Locale('en', 'US'), Locale('ar','AE')],
  1. Write This Function in your main
Locale _setLanguage() {
  Locale _locale;
  final _box = Hive.box(kConfigDBKey);//kConfigDBKey is Db key to store user select lang
  final String _language = _box.get(kConfigBoxFieldLang).toString();//kConfigBoxFieldLang is variable Key to get user selected lang
  switch (_language) {
    case 'ar':
      _locale = const Locale('ar', 'AE');
      break;
    case 'en':
      _locale = const Locale('en', 'US');
      break;
    default:
      _locale = const Locale('en', 'US');
  }
  return _locale;
}
  1. Invoke Base Widget My App from the button you want to changes App Language(note context is Build context you can pass it in function parameters and then to the invocation)
MyApp.setLocale(context, _locale);
Get.updateLocale(_locale);

@jonataslaw Has this update been released?

Has this update been released?

not yet @Hamidrezana

@jonataslaw I still have problem after upgrading to new version and layout doesn't update.

Hy i have updated a patch in Get slack channel Utils section for RtL layoit
changes.
Please have a look at it

On Thu, 24 Sep 2020, 18:46 Hamidreza Nazemi, notifications@github.com
wrote:

@jonataslaw https://github.com/jonataslaw I still have problem after
upgrading to new version and layout doesn't update.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/jonataslaw/getx/issues/600#issuecomment-698354325,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AMQZ37WLSPU2F6N2WNY2ZXDSHNES5ANCNFSM4RJJ7DTA
.

any news about RTL support?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ad-on-is picture ad-on-is  Â·  3Comments

aytunch picture aytunch  Â·  4Comments

williamsilva-98 picture williamsilva-98  Â·  4Comments

R-Praveen picture R-Praveen  Â·  4Comments

wailashraf71 picture wailashraf71  Â·  4Comments