@@ -6,6 +6,7 @@ import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuthException;
6
6
import 'package:firebase_ui_localizations/firebase_ui_localizations.dart' ;
7
7
import 'package:flutter/cupertino.dart' ;
8
8
import 'package:flutter/material.dart' ;
9
+ import 'package:flutter/services.dart' show PlatformException;
9
10
10
11
import '../flows/phone_auth_flow.dart' ;
11
12
@@ -38,7 +39,7 @@ String? localizedErrorText(
38
39
/// A widget which displays error text for a given Firebase error code.
39
40
/// {@endtemplate}
40
41
class ErrorText extends StatelessWidget {
41
- /// A way to customize localized error messages.
42
+ /// A way to customize localized error messages for [FirebaseAuthException] .
42
43
///
43
44
/// Example usage:
44
45
/// ```dart
@@ -54,6 +55,19 @@ class ErrorText extends StatelessWidget {
54
55
FirebaseAuthException exception,
55
56
)? localizeError;
56
57
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
+
57
71
/// A way to customize the widget that is used across the library to show
58
72
/// error hints. By default a localized text is used with a color set to
59
73
/// [ColorScheme.error] under [MaterialApp] and
@@ -106,6 +120,10 @@ class ErrorText extends StatelessWidget {
106
120
}
107
121
}
108
122
123
+ if (exception is PlatformException && localizePlatformError != null ) {
124
+ text = localizePlatformError !(context, exception as PlatformException );
125
+ }
126
+
109
127
return Text (
110
128
text,
111
129
textAlign: textAlign,
0 commit comments