Overview
TheRegisterScreen allows new users to create accounts in the EV Sum 2 application. It features email and password input fields with comprehensive validation, voice dictation support for accessibility, and real-time feedback on registration success or errors.
File Location: com.demodogo.ev_sum_2.ui.auth.RegisterScreen.kt:70
Function Signature
Parameters
Callback function invoked when the user wants to return to the login screen. Triggered by clicking “¿Ya tienes cuenta? Inicia sesión”.
State Management
Registration State
Stores the user’s email input. Spaces are automatically filtered out during input.
Stores the user’s password input. Spaces are automatically filtered out during input.
Controls whether the password is displayed as plain text or masked with dots.
Displays feedback messages to the user (validation errors or success confirmation).
Determines whether the message card should use error or success styling.
Voice Dictation State
Specifies which field is being filled via voice (EMAIL or PASSWORD).
Indicates whether the speech recognition service is actively listening.
Stores error messages related to voice recognition failures.
Controls the visibility of the field selection dialog for voice dictation.
Flag to trigger speech recognition after microphone permission is granted.
Services & Controllers
AuthService
Handles user registration:register(email: String, password: String)- Creates a new user account with the provided credentials
SpeechController
Manages speech recognition for voice input:setListener()- Configures callbacks for speech recognition eventsstart()- Begins listening for speech inputstop()- Stops the speech recognition servicedestroy()- Cleans up speech recognition resources
Input Validation
The RegisterScreen performs comprehensive validation before account creation:RegisterScreen.kt:235-263
Validation Rules
- Email Validation - Uses
Validators.isValidEmail()to ensure proper email format - Password Requirements - Uses
Validators.isValidPassword()which requires:- Minimum 6 characters
- At least 1 letter
- At least 1 number
- Empty Field Check - Ensures both email and password are provided
User Interactions
Registration Flow
- User enters email address
- User enters password (with show/hide toggle)
- User clicks “Registrar” button
- Client-side validation runs
- If validation passes, account is created via
AuthService.register() - Success message is displayed and fields are cleared
- User can navigate back to login screen
Voice Dictation
The screen supports voice input for accessibility:- User clicks the “Voz” button
- Dialog prompts user to select field (Email or Contraseña)
- Microphone permission is requested if needed
- Speech recognition begins
- Partial results update the field in real-time
- Final result is normalized and set when complete
RegisterScreen.kt:115-140
Password Visibility Toggle
Users can toggle password visibility using the eye icon:RegisterScreen.kt:212-217
Error Handling
The screen provides user-friendly error messages for common speech recognition issues:RegisterScreen.kt:88-97
UI Components
The RegisterScreen uses Material 3 components:- Surface - Root container with background color
- OutlinedTextField - Email and password input fields
- Button - Registration action and voice dictation button
- Card - Success/error message display
- Icon - Visual indicators (PersonAdd, Email, Lock, Mic)
- AlertDialog - Field selection dialog for voice dictation
- IconButton - Password visibility toggle
Permissions
The screen requests the following Android permission:Manifest.permission.RECORD_AUDIO- Required for voice dictation functionality
RegisterScreen.kt:99-109
Success Handling
When registration succeeds:- Success message “Cuenta creada exitosamente” is displayed
- Email and password fields are cleared
- User can navigate back to login screen to sign in
The screen automatically clears the input fields after successful registration, allowing the user to immediately return to the login screen without seeing their credentials.
Example Usage
Best Practices
- Input Sanitization - Automatically removes spaces from email and password inputs
- Resource Cleanup - SpeechController is destroyed in
DisposableEffectto prevent memory leaks - State Persistence - User input is preserved with
rememberSaveableacross configuration changes - Clear Validation Messages - Provides specific, actionable error messages
- Accessibility - Voice dictation provides alternative input method for users with disabilities
- Security - Password is masked by default with optional visibility toggle