Skip to content

Instantly share code, notes, and snippets.

@RipplesCode
Created April 8, 2021 15:19
Show Gist options
  • Save RipplesCode/ac98bb574dc30f3864b0203fb8818cb1 to your computer and use it in GitHub Desktop.
Save RipplesCode/ac98bb574dc30f3864b0203fb8818cb1 to your computer and use it in GitHub Desktop.
Internationalization
import 'package:flutter/material.dart';
import 'package:flutter_getx/my_controller.dart';
import 'package:flutter_getx/my_controller_binding.dart';
import 'package:flutter_getx/next_screen.dart';
import 'package:flutter_getx/student.dart';
import 'package:flutter_getx/unknown_route.dart';
import 'package:get/get.dart';
import 'Messages.dart';
import 'home.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
MyController myController=Get.put(MyController());
@override
Widget build(BuildContext context) {
// TODO: implement build
return GetMaterialApp(
translations: Messages(), // your translations
locale: Locale('en', 'US'), // default locale // to get device locale Get.deviceLocale
fallbackLocale: Locale('en', 'US'), // fallback locale if wrong locale found
title: "Internationalization",
home: Scaffold(
appBar: AppBar(title: Text("Internationalization")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('hello'.tr,style: TextStyle(fontSize: 25,color: Colors.purple),),
RaisedButton(
child: Text("Hindi"),
onPressed: () {
myController.changeLanguage('hi','IN');
},
),
SizedBox(
height: 16,
),
RaisedButton(
child: Text("French"),
onPressed: () {
myController.changeLanguage('fr','FR');
},
),
SizedBox(
height: 16,
),
RaisedButton(
child: Text("English"),
onPressed: () {
myController.changeLanguage('en','US');
},
),
],
),
),
),
);
}
}
import 'package:get/get.dart';
class Messages extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'en_US': {
'hello': 'Hello',
},
'hi_IN': {
'hello': 'नमस्कार',
},
'fr_FR': {
'hello': 'Bonjour',
}
};
}
import 'dart:ui';
import 'package:flutter_getx/student.dart';
import 'package:get/get.dart';
class MyController extends GetxController
{
void changeLanguage(var param1,var param2)
{
var locale = Locale(param1, param2);
Get.updateLocale(locale);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment