Overview
TheLoginScreen provides the user authentication interface for the EV Sum 2 application. It features traditional email/password login with additional accessibility through voice dictation for both email and password fields. The screen includes input validation, error handling, and navigation to registration and password recovery flows.
File Location: com.demodogo.ev_sum_2.ui.auth.LoginScreen.kt:71
Function Signature
Parameters
Callback function invoked when login is successful. Typically navigates to the home screen.
Callback function invoked when user wants to create a new account. Navigates to the registration screen.
Callback function invoked when user clicks “¿Olvidaste tu contraseña?”. Navigates to the password recovery screen.
State Management
Authentication State
Stores the user’s email input. Spaces are automatically filtered out.
Stores the user’s password input. Spaces are automatically filtered out.
Controls whether the password is displayed as plain text or masked.
Displays feedback messages to the user (success or error).
Determines whether the message should be styled as an error or success.
Voice Dictation State
Specifies which field is being filled via voice (EMAIL or PASSWORD).
Indicates whether the speech recognition service is actively listening.
Stores voice recognition error messages.
Controls the visibility of the dialog that lets users choose which field to dictate.
Flag to trigger speech recognition after microphone permission is granted.
Services & Controllers
AuthService
Handles authentication operations:login(email: String, password: String)- Authenticates user credentials
SpeechController
Manages speech recognition:setListener()- Configures callbacks for speech eventsstart()- Begins listening for speech inputstop()- Stops the speech recognition servicedestroy()- Cleans up speech recognition resources
Speech Recognition Callbacks
The LoginScreen configures the following speech recognition listeners:LoginScreen.kt:118-146
User Interactions
Email and Password Login
The login flow includes comprehensive validation:LoginScreen.kt:260-284
Voice Dictation Workflow
- User clicks the “Voz” button
- Dialog appears asking which field to dictate (Email or Contraseña)
- User selects a field
- Microphone permission is requested if not already granted
- Speech recognition starts
- Partial results update the field in real-time
- Final result is normalized and set when user stops speaking
The voice dictation feature uses normalization functions
normalizeEmailFromSpeech() and normalizePasswordFromSpeech() to convert spoken words into proper email and password formats.Password Visibility Toggle
Users can show/hide password text:LoginScreen.kt:217-228
Error Handling
The screen provides user-friendly error messages for speech recognition issues:LoginScreen.kt:91-100
UI Components
The LoginScreen utilizes Material 3 components:- Surface - Root container with background color
- OutlinedTextField - Email and password input fields
- Button - Primary login action and voice dictation
- TextButton - Registration link
- Card - Message display (errors and success)
- Icon - Visual indicators (verified user, email, lock, mic)
- AlertDialog - Field selection for voice dictation
- Divider - Visual separator for alternative login methods
Input Validation
The screen validates user input before attempting login:- Empty Fields Check - Ensures both email and password are provided
- Email Format Validation - Uses
isBasicEmailValid()extension function - Automatic Space Removal - Prevents accidental spaces in credentials
LoginScreen.kt:189
Permissions
The screen requests the following Android permission for voice dictation:Manifest.permission.RECORD_AUDIO- Required for speech recognition
LoginScreen.kt:102-112
Example Usage
Best Practices
- Resource Cleanup - SpeechController is destroyed in
DisposableEffectto prevent memory leaks - State Persistence - All user input is preserved with
rememberSaveableacross configuration changes - Accessibility - Voice dictation provides an alternative input method for users with mobility challenges
- User Feedback - Clear, actionable error messages guide users to resolve issues
- Security - Password masking is enabled by default with optional visibility toggle