Skip to content

Commit

Permalink
Merge pull request #439 from 7iqc/initial_iso_code_field
Browse files Browse the repository at this point in the history
initial iso code field to specify which country code will be used at launch
  • Loading branch information
juliansteenbakker authored Sep 29, 2023
2 parents fe6b59c + b446718 commit 5ec967c
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/flutter_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class FlutterLogin extends StatefulWidget {
this.confirmSignupKeyboardType,
this.headerWidget,
this.onSwitchToAdditionalFields,
this.initialIsoCode,
}) : assert((logo is String?) || (logo is ImageProvider?)),
logo = logo is String ? AssetImage(logo) : logo as ImageProvider?;

Expand Down Expand Up @@ -446,6 +447,10 @@ class FlutterLogin extends StatefulWidget {
/// A widget that can be placed on top of the loginCard.
final Widget? headerWidget;

/// The initial Iso Code for the widget to show using [LoginUserType.intlPhone].
/// if not specified. This field will show ['US'] by default.
final String? initialIsoCode;

static String? defaultEmailValidator(String? value) {
if (value == null || value.isEmpty || !Regex.email.hasMatch(value)) {
return 'Invalid email!';
Expand Down Expand Up @@ -838,6 +843,8 @@ class _FlutterLoginState extends State<FlutterLogin>
confirmSignupKeyboardType:
widget.confirmSignupKeyboardType,
introWidget: widget.headerWidget,

initialIsoCode: widget.initialIsoCode,
),
),
Positioned(
Expand Down
14 changes: 13 additions & 1 deletion lib/src/widgets/animated_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class AnimatedTextFormField extends StatefulWidget {
this.autocorrect = false,
this.autofillHints,
this.tooltip,
required this.initialIsoCode,

}) : assert(
(inertiaController == null && inertiaDirection == null) ||
(inertiaController != null && inertiaDirection != null),
Expand Down Expand Up @@ -82,6 +84,8 @@ class AnimatedTextFormField extends StatefulWidget {
final FormFieldSetter<String>? onSaved;
final TextFieldInertiaDirection? inertiaDirection;
final InlineSpan? tooltip;
final String? initialIsoCode;


@override
State<AnimatedTextFormField> createState() => _AnimatedTextFormFieldState();
Expand Down Expand Up @@ -166,7 +170,10 @@ class _AnimatedTextFormFieldState extends State<AnimatedTextFormField> {
}

if (widget.userType == LoginUserType.intlPhone) {
_phoneNumberInitialValue = PhoneNumber(isoCode: 'US', dialCode: '+1');
_phoneNumberInitialValue = PhoneNumber(
isoCode: widget.initialIsoCode ?? 'US',
dialCode: '+1',
);
if (widget.controller?.value.text != null) {
try {
final parsed = pnp.PhoneNumber.parse(widget.controller!.value.text);
Expand Down Expand Up @@ -454,6 +461,8 @@ class AnimatedPasswordTextFormField extends StatefulWidget {
this.onFieldSubmitted,
this.onSaved,
this.autofillHints,
required this.initialIsoCode,

}) : assert(
(inertiaController == null && inertiaDirection == null) ||
(inertiaController != null && inertiaDirection != null),
Expand All @@ -474,6 +483,8 @@ class AnimatedPasswordTextFormField extends StatefulWidget {
final FormFieldSetter<String>? onSaved;
final TextFieldInertiaDirection? inertiaDirection;
final Iterable<String>? autofillHints;
final String? initialIsoCode;


@override
State<AnimatedPasswordTextFormField> createState() =>
Expand Down Expand Up @@ -533,6 +544,7 @@ class _AnimatedPasswordTextFormFieldState
onFieldSubmitted: widget.onFieldSubmitted,
onSaved: widget.onSaved,
inertiaDirection: widget.inertiaDirection,
initialIsoCode: widget.initialIsoCode,
);
}
}
6 changes: 6 additions & 0 deletions lib/src/widgets/cards/additional_signup_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class _AdditionalSignUpCard extends StatefulWidget {
this.loginTheme,
required this.onSubmitCompleted,
required this.loadingController,
required this.initialIsoCode,

}) {
if (formFields.isEmpty) {
throw RangeError('The formFields array must not be empty');
Expand All @@ -23,6 +25,8 @@ class _AdditionalSignUpCard extends StatefulWidget {
final VoidCallback onSubmitCompleted;
final LoginTheme? loginTheme;
final AnimationController loadingController;
final String? initialIsoCode;


@override
_AdditionalSignUpCardState createState() => _AdditionalSignUpCardState();
Expand Down Expand Up @@ -192,6 +196,8 @@ class _AdditionalSignUpCardState extends State<_AdditionalSignUpCard>
: TextInputAction.next,
validator: formField.fieldValidator,
tooltip: formField.tooltip,

initialIsoCode: widget.initialIsoCode,
),
const SizedBox(
height: 5,
Expand Down
14 changes: 14 additions & 0 deletions lib/src/widgets/cards/auth_card_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class AuthCard extends StatefulWidget {
required this.scrollable,
required this.confirmSignupKeyboardType,
this.introWidget,
required this.initialIsoCode,

});

final EdgeInsets padding;
Expand All @@ -76,6 +78,8 @@ class AuthCard extends StatefulWidget {
final bool scrollable;
final TextInputType? confirmSignupKeyboardType;
final Widget? introWidget;
final String? initialIsoCode;


@override
AuthCardState createState() => AuthCardState();
Expand Down Expand Up @@ -374,6 +378,8 @@ class AuthCardState extends State<AuthCard> with TickerProviderStateMixin {
loginAfterSignUp: widget.loginAfterSignUp,
hideProvidersTitle: widget.hideProvidersTitle,
introWidget: widget.introWidget,

initialIsoCode: widget.initialIsoCode,
),
);
case _recoveryIndex:
Expand All @@ -391,6 +397,8 @@ class AuthCardState extends State<AuthCard> with TickerProviderStateMixin {
_changeCard(_loginPageIndex);
}
},

initialIsoCode: widget.initialIsoCode,
);

case _additionalSignUpIndex:
Expand Down Expand Up @@ -420,6 +428,8 @@ class AuthCardState extends State<AuthCard> with TickerProviderStateMixin {
_changeCard(_loginPageIndex);
}
},

initialIsoCode: widget.initialIsoCode,
),
);

Expand All @@ -429,6 +439,8 @@ class AuthCardState extends State<AuthCard> with TickerProviderStateMixin {
passwordValidator: widget.passwordValidator!,
onBack: () => _changeCard(_loginPageIndex),
onSubmitCompleted: () => _changeCard(_loginPageIndex),

initialIsoCode: widget.initialIsoCode,
);

case _confirmSignup:
Expand All @@ -451,6 +463,8 @@ class AuthCardState extends State<AuthCard> with TickerProviderStateMixin {
},
loginAfterSignUp: widget.loginAfterSignUp,
keyboardType: widget.confirmSignupKeyboardType,

initialIsoCode: widget.initialIsoCode,
),
);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/src/widgets/cards/login_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class _LoginCard extends StatefulWidget {
this.loginAfterSignUp = true,
this.hideProvidersTitle = false,
this.introWidget,
required this.initialIsoCode,

});

final AnimationController loadingController;
Expand All @@ -37,6 +39,8 @@ class _LoginCard extends StatefulWidget {
final bool requireAdditionalSignUpFields;
final Future<bool> Function() requireSignUpConfirmation;
final Widget? introWidget;
final String? initialIsoCode;


@override
_LoginCardState createState() => _LoginCardState();
Expand Down Expand Up @@ -365,6 +369,8 @@ class _LoginCardState extends State<_LoginCard> with TickerProviderStateMixin {
validator: widget.userValidator,
onSaved: (value) => auth.email = value!,
enabled: !_isSubmitting,

initialIsoCode: widget.initialIsoCode,
);
}

Expand Down Expand Up @@ -394,6 +400,8 @@ class _LoginCardState extends State<_LoginCard> with TickerProviderStateMixin {
validator: widget.passwordValidator,
onSaved: (value) => auth.password = value!,
enabled: !_isSubmitting,

initialIsoCode: widget.initialIsoCode,
);
}

Expand Down Expand Up @@ -422,6 +430,8 @@ class _LoginCardState extends State<_LoginCard> with TickerProviderStateMixin {
}
: (value) => null,
onSaved: (value) => auth.confirmPassword = value!,

initialIsoCode: widget.initialIsoCode,
);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/cards/recover_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class _RecoverCard extends StatefulWidget {
required this.navigateBack,
required this.onSubmitCompleted,
required this.loadingController,
required this.initialIsoCode,

});

final FormFieldValidator<String>? userValidator;
Expand All @@ -19,6 +21,8 @@ class _RecoverCard extends StatefulWidget {
final AnimationController loadingController;

final VoidCallback onSubmitCompleted;
final String? initialIsoCode;


@override
_RecoverCardState createState() => _RecoverCardState();
Expand Down Expand Up @@ -100,6 +104,8 @@ class _RecoverCardState extends State<_RecoverCard>
onFieldSubmitted: (value) => _submit(),
validator: widget.userValidator,
onSaved: (value) => auth.email = value!,

initialIsoCode: widget.initialIsoCode,
);
}

Expand Down
10 changes: 10 additions & 0 deletions lib/src/widgets/cards/recover_confirm_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ class _ConfirmRecoverCard extends StatefulWidget {
required this.passwordValidator,
required this.onBack,
required this.onSubmitCompleted,
required this.initialIsoCode,

});

final FormFieldValidator<String> passwordValidator;
final VoidCallback onBack;
final VoidCallback onSubmitCompleted;
final String? initialIsoCode;


@override
_ConfirmRecoverCardState createState() => _ConfirmRecoverCardState();
Expand Down Expand Up @@ -98,6 +102,8 @@ class _ConfirmRecoverCardState extends State<_ConfirmRecoverCard>
return null;
},
onSaved: (value) => _code = value!,

initialIsoCode: widget.initialIsoCode,
);
}

Expand All @@ -116,6 +122,8 @@ class _ConfirmRecoverCardState extends State<_ConfirmRecoverCard>
final auth = Provider.of<Auth>(context, listen: false);
auth.password = value!;
},

initialIsoCode: widget.initialIsoCode,
);
}

Expand All @@ -132,6 +140,8 @@ class _ConfirmRecoverCardState extends State<_ConfirmRecoverCard>
}
return null;
},

initialIsoCode: widget.initialIsoCode,
);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/cards/signup_confirm_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ class _ConfirmSignupCard extends StatefulWidget {
this.loginAfterSignUp = true,
required this.loadingController,
required this.keyboardType,
required this.initialIsoCode,

});

final bool loginAfterSignUp;
final VoidCallback onBack;
final VoidCallback onSubmitCompleted;
final AnimationController loadingController;
final TextInputType? keyboardType;
final String? initialIsoCode;


@override
_ConfirmSignupCardState createState() => _ConfirmSignupCardState();
Expand Down Expand Up @@ -140,6 +144,8 @@ class _ConfirmSignupCardState extends State<_ConfirmSignupCard>
},
onSaved: (value) => _code = value!,
keyboardType: widget.keyboardType,

initialIsoCode: widget.initialIsoCode,
);
}

Expand Down

0 comments on commit 5ec967c

Please sign in to comment.