Skip to content

Commit

Permalink
feat: add error exclusion list for login providers
Browse files Browse the repository at this point in the history
  • Loading branch information
juliansteenbakker committed Sep 29, 2023
1 parent eca8225 commit 57380a6
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 47 deletions.
22 changes: 12 additions & 10 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ packages:
path: ".."
relative: true
source: path
version: "4.2.0"
version: "4.2.1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -122,10 +122,11 @@ packages:
intl_phone_number_input:
dependency: transitive
description:
name: intl_phone_number_input
sha256: b812c6e3924e56e65b9684076ccd8eb24126abe0c84091d35d75a25e613a1793
url: "https://pub.dev"
source: hosted
path: "."
ref: improvements_with_updated_libphonenumber
resolved-ref: "8a5649ef7bd64cbb6fc6012338d854fb5e1b15f7"
url: "https://github.com/juliansteenbakker/intl_phone_number_input"
source: git
version: "0.7.3+1"
js:
dependency: transitive
Expand All @@ -146,11 +147,12 @@ packages:
libphonenumber_plugin:
dependency: transitive
description:
name: libphonenumber_plugin
sha256: d95a0f799936e6e243cd0be151af9a6f09286bbb2c513d517dad548c4b3eb70e
url: "https://pub.dev"
source: hosted
version: "0.3.2"
path: libphonenumber_plugin
ref: improvements
resolved-ref: b7c134c4f4031d67dc57756305b03cd2e1bc9284
url: "https://github.com/juliansteenbakker/plugin_libphonenumber"
source: git
version: "0.4.0"
libphonenumber_web:
dependency: transitive
description:
Expand Down
10 changes: 9 additions & 1 deletion lib/flutter_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ class LoginProvider {
/// Default: true
final bool animated;

/// Provide a list of errors to not display when a login has failed.
/// For example, if the login is cancelled and you don't want to show a error
/// message that the login is cancelled. If you provide the error message to this list
/// the error is not shown
///
/// Default: null
final List<String>? errorsToExcludeFromErrorMessage;

const LoginProvider({
this.button,
this.icon,
required this.callback,
this.errorsToExcludeFromErrorMessage,
this.label = '',
this.providerNeedsSignUpCallback,
this.animated = true,
Expand Down Expand Up @@ -843,7 +852,6 @@ class _FlutterLoginState extends State<FlutterLogin>
confirmSignupKeyboardType:
widget.confirmSignupKeyboardType,
introWidget: widget.headerWidget,

initialIsoCode: widget.initialIsoCode,
),
),
Expand Down
8 changes: 2 additions & 6 deletions lib/src/widgets/animated_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class AnimatedTextFormField extends StatefulWidget {
this.autofillHints,
this.tooltip,
required this.initialIsoCode,

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


@override
State<AnimatedTextFormField> createState() => _AnimatedTextFormFieldState();
Expand Down Expand Up @@ -359,7 +357,7 @@ class _AnimatedTextFormFieldState extends State<AnimatedTextFormField> {
color: Theme.of(context).textTheme.bodyMedium!.color,
size: Theme.of(context).textTheme.bodyMedium!.fontSize,
),
)
),
],
),
)
Expand Down Expand Up @@ -409,7 +407,7 @@ class _AnimatedTextFormFieldState extends State<AnimatedTextFormField> {
color: theme.primaryColor,
iconSize: 28,
icon: const Icon(Icons.info),
)
),
],
);
}
Expand Down Expand Up @@ -462,7 +460,6 @@ class AnimatedPasswordTextFormField extends StatefulWidget {
this.onSaved,
this.autofillHints,
required this.initialIsoCode,

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


@override
State<AnimatedPasswordTextFormField> createState() =>
Expand Down
4 changes: 1 addition & 3 deletions lib/src/widgets/cards/additional_signup_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class _AdditionalSignUpCard extends StatefulWidget {
required this.onSubmitCompleted,
required this.loadingController,
required this.initialIsoCode,

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


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

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

});

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


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

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

initialIsoCode: widget.initialIsoCode,
);

Expand Down Expand Up @@ -428,7 +424,6 @@ class AuthCardState extends State<AuthCard> with TickerProviderStateMixin {
_changeCard(_loginPageIndex);
}
},

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

initialIsoCode: widget.initialIsoCode,
);

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

initialIsoCode: widget.initialIsoCode,
),
);
Expand Down
11 changes: 5 additions & 6 deletions lib/src/widgets/cards/login_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class _LoginCard extends StatefulWidget {
this.hideProvidersTitle = false,
this.introWidget,
required this.initialIsoCode,

});

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


@override
_LoginCardState createState() => _LoginCardState();
Expand Down Expand Up @@ -271,7 +269,11 @@ class _LoginCardState extends State<_LoginCard> with TickerProviderStateMixin {
final messages = Provider.of<LoginMessages>(context, listen: false);

if (!DartHelper.isNullOrEmpty(error)) {
showErrorToast(context, messages.flushbarTitleError, error!);
// Only show error toast if error is not in exclusion list
if (loginProvider.errorsToExcludeFromErrorMessage == null ||
!loginProvider.errorsToExcludeFromErrorMessage!.contains(error)) {
showErrorToast(context, messages.flushbarTitleError, error!);
}
return false;
}

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

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

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

initialIsoCode: widget.initialIsoCode,
);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/src/widgets/cards/recover_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class _RecoverCard extends StatefulWidget {
required this.onSubmitCompleted,
required this.loadingController,
required this.initialIsoCode,

});

final FormFieldValidator<String>? userValidator;
Expand All @@ -22,7 +21,6 @@ class _RecoverCard extends StatefulWidget {

final VoidCallback onSubmitCompleted;
final String? initialIsoCode;


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

initialIsoCode: widget.initialIsoCode,
);
}
Expand Down
5 changes: 0 additions & 5 deletions lib/src/widgets/cards/recover_confirm_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ class _ConfirmRecoverCard extends StatefulWidget {
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 @@ -102,7 +100,6 @@ class _ConfirmRecoverCardState extends State<_ConfirmRecoverCard>
return null;
},
onSaved: (value) => _code = value!,

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

initialIsoCode: widget.initialIsoCode,
);
}
Expand All @@ -140,7 +136,6 @@ class _ConfirmRecoverCardState extends State<_ConfirmRecoverCard>
}
return null;
},

initialIsoCode: widget.initialIsoCode,
);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/src/widgets/cards/signup_confirm_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class _ConfirmSignupCard extends StatefulWidget {
required this.loadingController,
required this.keyboardType,
required this.initialIsoCode,

});

final bool loginAfterSignUp;
Expand All @@ -18,7 +17,6 @@ class _ConfirmSignupCard extends StatefulWidget {
final AnimationController loadingController;
final TextInputType? keyboardType;
final String? initialIsoCode;


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

initialIsoCode: widget.initialIsoCode,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/term_of_service_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _TermCheckboxState extends State<TermCheckbox> {
color: Theme.of(context).textTheme.bodyMedium!.color,
size: Theme.of(context).textTheme.bodyMedium!.fontSize,
),
)
),
],
),
)
Expand Down
4 changes: 2 additions & 2 deletions test/flutter_login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ void main() {
callback: () {
return null;
},
)
),
],
messages: LoginMessages(
signupButton: 'REGISTER',
Expand Down Expand Up @@ -977,7 +977,7 @@ void main() {
callback: () {
return null;
},
)
),
],
messages: LoginMessages(
signupButton: 'REGISTER',
Expand Down

0 comments on commit 57380a6

Please sign in to comment.