Skip to content

Commit cbe75ca

Browse files
authored
feat(ui_auth): add a way to customize PlatformException text (#171)
1 parent b69c8ed commit cbe75ca

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Diff for: packages/firebase_ui_auth/lib/src/widgets/error_text.dart

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuthException;
66
import 'package:firebase_ui_localizations/firebase_ui_localizations.dart';
77
import 'package:flutter/cupertino.dart';
88
import 'package:flutter/material.dart';
9+
import 'package:flutter/services.dart' show PlatformException;
910

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

@@ -38,7 +39,7 @@ String? localizedErrorText(
3839
/// A widget which displays error text for a given Firebase error code.
3940
/// {@endtemplate}
4041
class ErrorText extends StatelessWidget {
41-
/// A way to customize localized error messages.
42+
/// A way to customize localized error messages for [FirebaseAuthException].
4243
///
4344
/// Example usage:
4445
/// ```dart
@@ -54,6 +55,19 @@ class ErrorText extends StatelessWidget {
5455
FirebaseAuthException exception,
5556
)? localizeError;
5657

58+
/// A way to customize error message for [PlatformException]
59+
///
60+
/// Example usage:
61+
/// ```dart
62+
/// ErrorText.localizePlatformError = (BuildContext context, PlatformException e) {
63+
/// if (e.code == "network_error") return "Please check your internet connection.";
64+
/// return "Oh no! Something went wrong.";
65+
/// }
66+
static String Function(
67+
BuildContext context,
68+
PlatformException exception,
69+
)? localizePlatformError;
70+
5771
/// A way to customize the widget that is used across the library to show
5872
/// error hints. By default a localized text is used with a color set to
5973
/// [ColorScheme.error] under [MaterialApp] and
@@ -106,6 +120,10 @@ class ErrorText extends StatelessWidget {
106120
}
107121
}
108122

123+
if (exception is PlatformException && localizePlatformError != null) {
124+
text = localizePlatformError!(context, exception as PlatformException);
125+
}
126+
109127
return Text(
110128
text,
111129
textAlign: textAlign,

0 commit comments

Comments
 (0)