From 98e66abd758f36cc6fb375078ac176a14278b383 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:17:57 -0500 Subject: [PATCH] fix: override text field's default error styling to remove gap but still show error outline on username field (#1726) --- lib/pages/login/login.dart | 4 ++-- lib/pangea/login/pages/pangea_login_view.dart | 2 ++ .../login/widgets/full_width_button.dart | 24 ++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index d4f2c90a3..793eade81 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -208,7 +208,7 @@ class LoginController extends State { // setState(() => passwordError = exception.errorMessage); setState(() { passwordError = exception.errorMessage; - usernameError = ""; + usernameError = exception.errorMessage; }); // Pangea# return setState(() => loadingSignIn = false); @@ -217,7 +217,7 @@ class LoginController extends State { // setState(() => passwordError = exception.toString()); setState(() { passwordError = exception.toString(); - usernameError = ""; + usernameError = exception.toString(); }); // Pangea# return setState(() => loadingSignIn = false); diff --git a/lib/pangea/login/pages/pangea_login_view.dart b/lib/pangea/login/pages/pangea_login_view.dart index c4e0d3702..92e24f715 100644 --- a/lib/pangea/login/pages/pangea_login_view.dart +++ b/lib/pangea/login/pages/pangea_login_view.dart @@ -30,6 +30,8 @@ class PangeaLoginView extends StatelessWidget { }, controller: controller.usernameController, errorText: controller.usernameError, + showErrorText: controller.usernameError != null && + controller.passwordError == null, ), FullWidthTextField( hintText: L10n.of(context).password, diff --git a/lib/pangea/login/widgets/full_width_button.dart b/lib/pangea/login/widgets/full_width_button.dart index 831218279..47ccdf4e8 100644 --- a/lib/pangea/login/widgets/full_width_button.dart +++ b/lib/pangea/login/widgets/full_width_button.dart @@ -118,8 +118,10 @@ class FullWidthTextField extends StatelessWidget { final TextInputType? keyboardType; final String? Function(String?)? validator; final TextEditingController? controller; + final bool? showErrorText; final String? errorText; final Function(String)? onSubmitted; + final InputDecoration? decoration; const FullWidthTextField({ required this.hintText, @@ -130,12 +132,16 @@ class FullWidthTextField extends StatelessWidget { this.validator, this.controller, this.errorText, + this.showErrorText, this.onSubmitted, + this.decoration, super.key, }); @override Widget build(BuildContext context) { + final bool shouldShowError = showErrorText ?? errorText != null; + return Padding( padding: const EdgeInsets.all(6.0), child: TextFormField( @@ -148,8 +154,24 @@ class FullWidthTextField extends StatelessWidget { border: OutlineInputBorder( borderRadius: BorderRadius.circular(36.0), ), + enabledBorder: errorText != null + ? OutlineInputBorder( + borderRadius: BorderRadius.circular(36.0), + borderSide: + BorderSide(color: Theme.of(context).colorScheme.error), + ) + : null, + focusedBorder: errorText != null + ? OutlineInputBorder( + borderRadius: BorderRadius.circular(36.0), + borderSide: BorderSide( + color: Theme.of(context).colorScheme.error, + width: 2, + ), + ) + : null, contentPadding: const EdgeInsets.symmetric(horizontal: 30), - errorText: errorText, + errorText: shouldShowError ? errorText : null, ), validator: validator, onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),