Skip to content

Commit ab89f5c

Browse files
authored
feat(ui_auth): export localizedErrorText (#189)
When `ErrorText.localizeError` is used, it becomes a single source of truth. This means all error messages should be localized by developer. A subset of errors is already localized by Firebase UI, so `localizedErrorText` that is used internally is now public and could be used inside `ErrorText.localizeError`. Example: ```dart ErrorText.localizeError = (BuildContext context, FirebaseAuthException e) { if (e.code == "user-not-found" || e.code == "wrong-password") return "Wrong credentials"; final defaultLabels = FirebaseUILocalizations.labelsOf(context); return localizedErrorText(e.code, defaultLabels); } ```
1 parent e85c516 commit ab89f5c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/firebase_ui_auth/lib/firebase_ui_auth.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export 'src/widgets/email_form.dart'
8181
export 'src/widgets/email_input.dart';
8282
export 'src/widgets/email_link_sign_in_button.dart';
8383
export 'src/widgets/email_sign_up_dialog.dart';
84-
export 'src/widgets/error_text.dart' show ErrorText;
84+
export 'src/widgets/error_text.dart' show ErrorText, localizedErrorText;
8585
export 'src/widgets/forgot_password_button.dart';
8686
export 'src/widgets/internal/oauth_provider_button.dart'
8787
show OAuthProviderButton, OAuthButtonVariant;

packages/firebase_ui_auth/lib/src/widgets/error_text.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ class ErrorText extends StatelessWidget {
4343
///
4444
/// Example usage:
4545
/// ```dart
46-
/// ErrorText.localizeError = (BuildContext context, fba.FirebaseAuthException e) {
46+
/// ErrorText.localizeError = (BuildContext context, FirebaseAuthException e) {
47+
/// final defaultLabels = FirebaseUILocalizations.labelsOf(context);
48+
///
4749
/// return switch (e.code) {
4850
/// 'user-not-found' => 'Please create an account first.',
4951
/// 'credential-already-in-use' => 'This email is already in use.',
50-
/// _ => 'Oh no! Something went wrong.'
52+
/// _ => localizedErrorText(e.code, defaultLabels) ?? 'Oh no! Something went wrong.',
5153
/// }
5254
/// }
5355
static String Function(

0 commit comments

Comments
 (0)