Getx: Do you have some example on how to use getx internationalization?

Created on 27 Jun 2020  路  6Comments  路  Source: jonataslaw/getx

i've noticed that you already have code for translation, but i did not saw any examples.

I'm not very good in understand your source code and apply that, can you give us a little example?

if you have time, can you please explain how to use all those new methods in GetUtils?

Most helpful comment

Localizations:
translations

All 6 comments

Localizations:
translations

I tried the example but it is not updating after pushing the button. Is this a bug or a typo in the sample code @jonataslaw ?

import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      locale: Locale('nl', 'BE'),
      translationsKeys: {
        'nl_BE': {'title': 'Hallo van GetX'},
        'en_US': {'title': 'Hello from GetX'}
      },
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('title'.tr),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('title'.tr),
            RaisedButton(
              child: Text('Switch to English'),
              onPressed: () {
                print('switching to EN');
                Get.updateLocale(Locale('en', 'US'));
              },
            )
          ],
        ),
      ),
    );
  }
}

maybe need to call Get().getController.restartApp(); after updateLocale ?

Currently Flutter has transformed the home into a constant, making it have a permanent state. You can change the MaterialApp as many times as you like, they put home inside a const, which prevents the update when the parent rebuilds. If you create another class for your text widget, it changes, because the child of home will not be a constant unless you do: child: const TextWidget (). This was introduced at 1.17, lol, and does not happen with named routes. I will force the update of the home when the locale is changed, and update now, with Stefan's PRs for GetUtils.

maybe need to call Get().getController.restartApp(); after updateLocale ?

This in this current update is necessary, but it will not be more, because I will update how things work.

closing since i got what i wanted 馃槃 thank you @jonataslaw

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rupamking1 picture rupamking1  路  3Comments

R-Praveen picture R-Praveen  路  4Comments

aztecrabbit picture aztecrabbit  路  3Comments

manojeeva picture manojeeva  路  3Comments

NO-ob picture NO-ob  路  4Comments