feat(01-09): integrate enhanced auth components into auth pages
Updated login and signup pages: - Replace inline error displays with AuthForm.formWideError - Add onErrorDismissed callbacks for better UX - Maintain consistent error handling across auth flows Updated password reset form: - Add form-wide error display matching AuthForm style - Add field-specific error styling with icons - Implement auto-clear error when user starts typing - Add accessibility announcements for error clearing - Maintain consistent visual hierarchy
This commit is contained in:
@@ -98,42 +98,13 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
|||||||
submitButtonText: 'Sign In',
|
submitButtonText: 'Sign In',
|
||||||
isLoading: _isLoading,
|
isLoading: _isLoading,
|
||||||
autofocusEmail: true,
|
autofocusEmail: true,
|
||||||
),
|
formWideError: _errorMessage,
|
||||||
const SizedBox(height: 16),
|
onErrorDismissed: () {
|
||||||
|
setState(() {
|
||||||
// Error message display
|
_errorMessage = null;
|
||||||
if (_errorMessage != null) ...[
|
});
|
||||||
Container(
|
},
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.errorContainer,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(
|
|
||||||
color: Theme.of(context).colorScheme.error,
|
|
||||||
width: 1,
|
|
||||||
),
|
),
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.error_outline,
|
|
||||||
size: 20,
|
|
||||||
color: Theme.of(context).colorScheme.error,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
_errorMessage!,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: Theme.of(context).colorScheme.onErrorContainer,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
],
|
|
||||||
|
|
||||||
// Forgot password link
|
// Forgot password link
|
||||||
Align(
|
Align(
|
||||||
|
|||||||
@@ -109,42 +109,13 @@ class _SignupPageState extends ConsumerState<SignupPage> {
|
|||||||
submitButtonText: 'Create Account',
|
submitButtonText: 'Create Account',
|
||||||
isLoading: _isLoading,
|
isLoading: _isLoading,
|
||||||
autofocusEmail: true,
|
autofocusEmail: true,
|
||||||
|
formWideError: _errorMessage,
|
||||||
|
onErrorDismissed: () {
|
||||||
|
setState(() {
|
||||||
|
_errorMessage = null;
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// Error message display
|
|
||||||
if (_errorMessage != null) ...[
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.errorContainer,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(
|
|
||||||
color: Theme.of(context).colorScheme.error,
|
|
||||||
width: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.error_outline,
|
|
||||||
size: 20,
|
|
||||||
color: Theme.of(context).colorScheme.error,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
_errorMessage!,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: Theme.of(context).colorScheme.onErrorContainer,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
],
|
|
||||||
|
|
||||||
// Terms and conditions checkbox
|
// Terms and conditions checkbox
|
||||||
_buildTermsCheckbox(),
|
_buildTermsCheckbox(),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter/semantics.dart';
|
||||||
import 'auth_button.dart';
|
import 'auth_button.dart';
|
||||||
|
|
||||||
/// Reusable password reset form with email validation and submission
|
/// Reusable password reset form with email validation and submission
|
||||||
@@ -37,6 +38,7 @@ class PasswordResetForm extends StatefulWidget {
|
|||||||
|
|
||||||
class _PasswordResetFormState extends State<PasswordResetForm> {
|
class _PasswordResetFormState extends State<PasswordResetForm> {
|
||||||
String? _emailError;
|
String? _emailError;
|
||||||
|
String? _lastAnnouncedError;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -70,7 +72,16 @@ class _PasswordResetFormState extends State<PasswordResetForm> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
|
// Form-wide error display
|
||||||
|
if (widget.errorMessage != null) ...[
|
||||||
|
_buildFormWideError(),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
_buildEmailField(),
|
_buildEmailField(),
|
||||||
|
if (_emailError != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildFieldError(_emailError!),
|
||||||
|
],
|
||||||
if (widget.helperText != null) ...[
|
if (widget.helperText != null) ...[
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
_buildHelperText(),
|
_buildHelperText(),
|
||||||
@@ -146,12 +157,8 @@ class _PasswordResetFormState extends State<PasswordResetForm> {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
// Clear error when user starts typing
|
// Clear errors when user starts typing
|
||||||
if (_emailError != null) {
|
_clearErrorsOnUserInput();
|
||||||
setState(() {
|
|
||||||
_emailError = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Call external callback if provided
|
// Call external callback if provided
|
||||||
if (widget.onEmailChanged != null) {
|
if (widget.onEmailChanged != null) {
|
||||||
widget.onEmailChanged!(value);
|
widget.onEmailChanged!(value);
|
||||||
@@ -192,6 +199,88 @@ class _PasswordResetFormState extends State<PasswordResetForm> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds form-wide error display
|
||||||
|
Widget _buildFormWideError() {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.errorContainer,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.error_outline,
|
||||||
|
size: 20,
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
widget.errorMessage!,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.onErrorContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds field-specific error display
|
||||||
|
Widget _buildFieldError(String error) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.errorContainer.withOpacity(0.5),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
border: Border.left(
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
width: 3,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.info_outline,
|
||||||
|
size: 16,
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
error,
|
||||||
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clears errors when user starts typing
|
||||||
|
void _clearErrorsOnUserInput() {
|
||||||
|
bool hadError = _emailError != null || widget.errorMessage != null;
|
||||||
|
|
||||||
|
if (hadError && _lastAnnouncedError != widget.errorMessage) {
|
||||||
|
_announceForAccessibility('Error cleared');
|
||||||
|
_lastAnnouncedError = widget.errorMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Announces messages for screen readers
|
||||||
|
void _announceForAccessibility(String message) {
|
||||||
|
SemanticsService.announce(message, TextDirection.ltr);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildSubmitButton() {
|
Widget _buildSubmitButton() {
|
||||||
return AuthButton(
|
return AuthButton(
|
||||||
text: widget.submitButtonText,
|
text: widget.submitButtonText,
|
||||||
|
|||||||
Reference in New Issue
Block a user