File tree 3 files changed +39
-4
lines changed
packages/firebase_ui_auth
3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ class _PhoneInputViewState extends State<PhoneInputView> {
90
90
@override
91
91
Widget build (BuildContext context) {
92
92
final l = FirebaseUILocalizations .labelsOf (context);
93
- final countryCode = Localizations .localeOf (context).countryCode;
93
+ final countryCode = Localizations .localeOf (context).countryCode ??
94
+ WidgetsBinding .instance.platformDispatcher.locale.countryCode;
94
95
95
96
return AuthFlowBuilder <PhoneAuthController >(
96
97
flowKey: widget.flowKey,
@@ -121,7 +122,7 @@ class _PhoneInputViewState extends State<PhoneInputView> {
121
122
widget.subtitleBuilder !(context),
122
123
if (state is AwaitingPhoneNumber || state is SMSCodeRequested ) ...[
123
124
PhoneInput (
124
- initialCountryCode: countryCode! ,
125
+ initialCountryCode: countryCode,
125
126
onSubmit: onSubmit (ctrl),
126
127
key: phoneInputKey,
127
128
),
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ class PhoneInput extends StatefulWidget {
85
85
86
86
/// An initial country code that should be selected in the country code
87
87
/// picker.
88
- final String initialCountryCode;
88
+ final String ? initialCountryCode;
89
89
90
90
/// Returns a phone number from the [PhoneInput] that was provided a [key] .
91
91
static String ? getPhoneNumber (GlobalKey <PhoneInputState > key) {
@@ -101,7 +101,7 @@ class PhoneInput extends StatefulWidget {
101
101
/// {@macro ui.auth.widgets.phone_input}
102
102
const PhoneInput ({
103
103
Key ? key,
104
- required this .initialCountryCode,
104
+ this .initialCountryCode,
105
105
this .onSubmit,
106
106
}) : super (key: key);
107
107
Original file line number Diff line number Diff line change
1
+ import 'package:firebase_ui_auth/src/widgets/phone_input.dart' ;
2
+ import 'package:flutter/material.dart' ;
3
+ import 'package:flutter_test/flutter_test.dart' ;
4
+
5
+ void main () {
6
+ group ('PhoneInput' , () {
7
+ testWidgets ('shows default country and country code' , (tester) async {
8
+ await tester.pumpWidget (
9
+ const MaterialApp (
10
+ home: Scaffold (
11
+ body: PhoneInput (initialCountryCode: 'US' ),
12
+ ),
13
+ ),
14
+ );
15
+
16
+ expect (find.text ('United States' ), findsOneWidget);
17
+ });
18
+
19
+ testWidgets (
20
+ 'prompts to select a country if initialCountryCode is null' ,
21
+ (tester) async {
22
+ await tester.pumpWidget (
23
+ const MaterialApp (
24
+ home: Scaffold (
25
+ body: PhoneInput (initialCountryCode: null ),
26
+ ),
27
+ ),
28
+ );
29
+
30
+ expect (find.text ('Choose a country' ), findsOneWidget);
31
+ },
32
+ );
33
+ });
34
+ }
You can’t perform that action at this time.
0 commit comments