1.Getx国际化
translations: Translation(),
locale: Locale('zh', 'CN'),
fallbackLocale: Locale('en', 'US'),
supportedLocales: Translation.supportedLocales,
class Translation extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'en':{
"hello":"hello"
},
'zh':{
'hello':'你好'
}
};
static const supportedLocales = [
Locale('en', 'US'),
Locale('zh', 'CN'),
];
}
class LanguagePage extends StatelessWidget {
const LanguagePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('多语言:'),
Text('hello'.tr),
ElevatedButton(onPressed: (){
var locale = Locale('zh','CN');
Get.updateLocale(locale);
}, child: Text("切换成中文")),
ElevatedButton(onPressed: (){
var locale = Locale('en','US');
Get.updateLocale(locale);
}, child: Text("切换成英文")),
],
);
}
}
yaml 中引入
# 本地化
flutter_localizations:
sdk: flutter
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
2.GetUtils工具类 是否是一个邮箱,是否是一个手机号,
TextField(
controller: editingController,
),
ElevatedButton(
onPressed: () {
if (GetUtils.isEmail(editingController.text)) {
Get.snackbar("是", "是邮箱");
} else {
Get.snackbar("不是", "不是邮箱");
}
},
child: Text("校验"))