Screen Overview
TheLoginScreen provides user authentication functionality with support for both email/password login and Google Sign-In. It includes terms and conditions acceptance and navigation to the registration screen.
Location: lib/ui/screens/login_screen.dart
Purpose
The LoginScreen serves as the entry point to the application, providing:- Email and password authentication
- Google Sign-In integration
- Terms and conditions acceptance
- Navigation to user registration
- Form validation and error handling
State Management
State Variables
Instance of the authentication service that handles sign-in operations.
Controller for the email input field.
Controller for the password input field.
Boolean flag indicating whether the user has accepted the terms and conditions. Initially
false.Authentication Methods
Email/Password Login
login_screen.dart:19.
Process:
- Trims email and password input
- Calls
_authService.signInWithEmailAndPassword() - On success: Navigates to
/homeroute - On failure: Shows error SnackBar
- Validates widget is still mounted before navigation
- Displays “Inicio de sesión fallido. Verifica tus credenciales.” on error
Google Sign-In
login_screen.dart:37.
Process:
- Calls
_authService.signInWithGoogle() - On success: Navigates to
/homeroute - On failure: Shows error SnackBar
- Validates widget is still mounted before navigation
- Displays “Error al iniciar sesión con Google.” on error
Form Components
Email Input Field
- Label: “Ingrese correo electrónico”
- Input type:
TextInputType.emailAddress - Border: Rounded (30.0 radius)
- Color scheme: Gray (#C9C9CA)
login_screen.dart:70-83.
Password Input Field
- Label: “Contraseña”
- Obscured text:
true - Border: Rounded (30.0 radius)
- Color scheme: Gray (#C9C9CA)
login_screen.dart:85-97.
Terms and Conditions Checkbox
- Label: “Acepto Términos y Condiciones” (clickable)
- Active color: Light gray (#E6E6E6)
- Check color: Green (#6BCE81)
- Tapping label opens terms dialog
login_screen.dart:99-127.
Buttons
Login Button
- State: Disabled unless terms are accepted
- Background: Teal (#B7F6E3)
- Border: Yellow (#FFEE93, 2px)
- Text: “Iniciar”
- Size: 200x50 minimum
login_screen.dart:129-147.
Google Sign-In Button
- Background: Teal (#089B83)
- Text: “Iniciar sesión con Google”
- Always enabled (no terms requirement)
login_screen.dart:154-160.
Register Navigation
- First part: Gray (#C9C9CA)
- “Regístrate”: Dark green (#0D4533)
login_screen.dart:161-183.
Terms and Conditions Dialog
Dialog Function
login_screen.dart:194.
Dialog Structure
Header
- Title: “Términos y Condiciones”
- Close button (circular, top-right)
Content
- Effective date: “02 de Octubre de 2024”
- Welcome message
- Section 1: Acceptance of Terms
- Rounded corners (20.0 radius)
- Max width: 350px
- Close button: Green circular border (#97CE6B)
- Scrollable content for long terms
Layout Structure
Form Validation
Input Validation
- Email: Uses
.trim()to remove whitespace - Password: Uses
.trim()to remove whitespace - Terms: Must be accepted before email/password login
Error Messages
Error messages are displayed usingScaffoldMessenger.showSnackBar():
Navigation Flow
Screen Features
Responsive Design
Responsive Design
SingleChildScrollViewprevents overflow on small screens- Container max-width constraint (400px) for larger screens
- Centered layout for better appearance
Accessibility
Accessibility
- Proper keyboard types (email, password)
- Visible labels on all inputs
- Clear error messaging
- Touch-friendly button sizes
UX Considerations
UX Considerations
- Visual branding with sunshine logo
- Disabled state for login button (requires terms acceptance)
- Separate Google Sign-In option (no terms requirement)
- Clear path to registration
Color Scheme
| Element | Color Code | Description |
|---|---|---|
| Background | #FFFFFF | White |
| Input borders | #C9C9CA | Light gray |
| Login button bg | #B7F6E3 | Teal |
| Login button border | #FFEE93 | Yellow |
| Google button bg | #089B83 | Dark teal |
| Terms checkbox | #6BCE81 | Green |
| Register link | #0D4533 | Dark green |
Best Practices
Uses
mounted check before navigation to prevent memory leaksTrims user input to avoid whitespace issues
Separates authentication logic into
AuthServiceProvides clear user feedback with SnackBars
Implements proper error handling for async operations