Skip to content

feat(ui_auth): add a way to customize PlatformException text #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/firebase_ui_auth/lib/src/widgets/error_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuthException;
import 'package:firebase_ui_localizations/firebase_ui_localizations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show PlatformException;

import '../flows/phone_auth_flow.dart';

Expand Down Expand Up @@ -38,7 +39,7 @@ String? localizedErrorText(
/// A widget which displays error text for a given Firebase error code.
/// {@endtemplate}
class ErrorText extends StatelessWidget {
/// A way to customize localized error messages.
/// A way to customize localized error messages for [FirebaseAuthException].
///
/// Example usage:
/// ```dart
Expand All @@ -54,6 +55,19 @@ class ErrorText extends StatelessWidget {
FirebaseAuthException exception,
)? localizeError;

/// A way to customize error message for [PlatformException]
///
/// Example usage:
/// ```dart
/// ErrorText.localizePlatformError = (BuildContext context, PlatformException e) {
/// if (e.code == "network_error") return "Please check your internet connection.";
/// return "Oh no! Something went wrong.";
/// }
static String Function(
BuildContext context,
PlatformException exception,
)? localizePlatformError;

/// A way to customize the widget that is used across the library to show
/// error hints. By default a localized text is used with a color set to
/// [ColorScheme.error] under [MaterialApp] and
Expand Down Expand Up @@ -106,6 +120,10 @@ class ErrorText extends StatelessWidget {
}
}

if (exception is PlatformException && localizePlatformError != null) {
text = localizePlatformError!(context, exception as PlatformException);
}

return Text(
text,
textAlign: textAlign,
Expand Down