Skip to content

Commit 392197b

Browse files
committed
fix(ui): allow null countryCode for phone input
1 parent 929e368 commit 392197b

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

packages/firebase_ui_auth/lib/src/views/phone_input_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class _PhoneInputViewState extends State<PhoneInputView> {
121121
widget.subtitleBuilder!(context),
122122
if (state is AwaitingPhoneNumber || state is SMSCodeRequested) ...[
123123
PhoneInput(
124-
initialCountryCode: countryCode!,
124+
initialCountryCode: countryCode,
125125
onSubmit: onSubmit(ctrl),
126126
key: phoneInputKey,
127127
),

packages/firebase_ui_auth/lib/src/widgets/phone_input.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class PhoneInput extends StatefulWidget {
8585

8686
/// An initial country code that should be selected in the country code
8787
/// picker.
88-
final String initialCountryCode;
88+
final String? initialCountryCode;
8989

9090
/// Returns a phone number from the [PhoneInput] that was provided a [key].
9191
static String? getPhoneNumber(GlobalKey<PhoneInputState> key) {
@@ -101,7 +101,7 @@ class PhoneInput extends StatefulWidget {
101101
/// {@macro ui.auth.widgets.phone_input}
102102
const PhoneInput({
103103
Key? key,
104-
required this.initialCountryCode,
104+
this.initialCountryCode,
105105
this.onSubmit,
106106
}) : super(key: key);
107107

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)