Skip to content

Instantly share code, notes, and snippets.

@Jonathanlight
Created April 5, 2019 15:01
Show Gist options
  • Save Jonathanlight/5c7bf54a09495e2d261d1110d1552c49 to your computer and use it in GitHub Desktop.
Save Jonathanlight/5c7bf54a09495e2d261d1110d1552c49 to your computer and use it in GitHub Desktop.
class MyHomeState extends State<MyHomePage> {
Locale currentLang;
int clicked = 0;
@override
void initState() {
super.initState();
new Future.delayed(Duration.zero, () async {
await FlutterI18n.refresh(context, new Locale('fr'));
setState(() {
currentLang = FlutterI18n.currentLocale(context);
});
});
}
changeLanguage() {
setState(() {
currentLang = currentLang.languageCode == 'fr'
? new Locale('en')
: new Locale('es');
});
}
language(String lang) {
setState(() {
new Future.delayed(Duration.zero, () async {
await FlutterI18n.refresh(context, new Locale(lang));
setState(() {
currentLang = FlutterI18n.currentLocale(context);
});
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment