我想使用本地化自定义我的 flutterfire ui 身份验证屏幕。通过此链接:https://firebase.flutter.dev/docs/ui/auth/localization/,我成功自定义了电子邮件和密码文本字段的标签。现在我想自定义 flutterfire ui auth 页面上的所有其他文本小部件。为了自定义电子邮件和密码文本字段的标签,我们使用了
@override
String get emailInputLabel => 'Enter your email';
@override
String get passwordInputLabel => 'Enter your password';
我如何对其他文本执行此操作?
您可以通过覆盖这些文本小部件的 getter 来自定义其他文本小部件。您可以覆盖的 getter 的完整列表可在 DefaultLocalizations 文档的属性部分中找到。
例如,要更新电话输入标签,您可以像这样重写
phoneInputLabel
getter:
@override
String get phoneInputLabel => 'Enter your phone number';
我设法使用包 firebase_ui_localizations 来做到这一点。例如,添加以下行以翻译为葡萄牙语:
MaterialApp(
title: 'Flutter Demo',
locale: const Locale('pt')
home: const LoginScreen(),
supportedLocales: const [
Locale('pt'),
],
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FirebaseUILocalizations.delegate,
],