@@ -6,6 +6,7 @@ import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuthException;
66import 'package:firebase_ui_localizations/firebase_ui_localizations.dart' ;
77import 'package:flutter/cupertino.dart' ;
88import 'package:flutter/material.dart' ;
9+ import 'package:flutter/services.dart' show PlatformException;
910
1011import '../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}
4041class 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