This commit is contained in:
Felipe
2024-02-26 17:33:28 -05:00
parent 11d9ee6d35
commit 25c898ba19
2 changed files with 104 additions and 92 deletions
+11 -6
View File
@@ -1,16 +1,22 @@
import 'package:flutter/material.dart';
class GenderDropdown extends StatefulWidget {
final Function(String) onChanged;
final TextEditingController controller;
const GenderDropdown({super.key, required this.onChanged});
const GenderDropdown({super.key, required this.controller});
@override
State<GenderDropdown> createState() => _GenderDropdownState();
}
class _GenderDropdownState extends State<GenderDropdown> {
String? selectedGender;
late TextEditingController controller;
@override
void initState() {
super.initState();
controller = widget.controller;
}
@override
Widget build(BuildContext context) {
@@ -28,15 +34,14 @@ class _GenderDropdownState extends State<GenderDropdown> {
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
isExpanded: true,
value: selectedGender,
value: controller.text,
hint: const Text(
'Selecciona tu género',
style: TextStyle(fontSize: 16.0),
),
onChanged: (String? newValue) {
setState(() {
selectedGender = newValue;
widget.onChanged(selectedGender!);
controller.text = newValue!;
});
},
items: ['Masculino', 'Femenino', 'Otro']
+93 -86
View File
@@ -1,5 +1,4 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:flutter/cupertino.dart';
@@ -24,6 +23,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
final TextEditingController _phoneController = TextEditingController();
final TextEditingController _birthdayController = TextEditingController();
final TextEditingController _genderController = TextEditingController();
XFile? _imageFile;
bool isLoading = false;
@@ -46,7 +46,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
isLoading = true;
});
} else if (state is UpdateUserInfoSuccess) {
// Snack bar
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Información actualizada'),
));
@@ -74,92 +73,101 @@ class _ProfileScreenState extends State<ProfileScreen> {
_nameController.text = state.user!.name ?? '';
_emailController.text = state.user!.email ?? '';
_phoneController.text = state.user!.phone ?? '';
_birthdayController.text = state.user!.birthday ?? '';
_genderController.text = state.user!.gender ?? '';
return SingleChildScrollView(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 40, vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
child: Stack(
children: [
pictureWidget(state, context),
const SizedBox(height: 20.0),
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Nombre',
prefixIcon: Icon(Icons.person),
hintText: 'Nombre (obligatorio)',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
pictureWidget(state, context),
const SizedBox(height: 20.0),
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Nombre',
prefixIcon: Icon(Icons.person),
hintText: 'Nombre (obligatorio)',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.red, width: 2.0),
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor, ingrese su nombre';
}
return null;
},
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0),
const SizedBox(height: 20.0),
TextFormField(
controller: _emailController,
decoration: const InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email_rounded),
hintText: 'Email',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.red, width: 2.0),
),
),
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor, ingrese su nombre';
}
return null;
},
const SizedBox(height: 20.0),
TextFormField(
controller: _phoneController,
decoration: const InputDecoration(
labelText: 'Número de Teléfono',
prefixIcon: Icon(Icons.phone_android_rounded),
hintText: '+57',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.red, width: 2.0),
),
),
),
const SizedBox(height: 20.0),
BirthdayPicker(
onDateSelected: (birthDay) {
_birthdayController.text =
DateFormat('dd/MM/yyyy').format(birthDay);
},
controller: _birthdayController,
),
const SizedBox(height: 20.0),
GenderDropdown(
controller: _genderController,
),
const SizedBox(height: 60.0),
saveButton(state, context),
],
),
const SizedBox(height: 20.0),
TextFormField(
controller: _emailController,
decoration: const InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email_rounded),
hintText: 'Email',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0),
),
),
),
const SizedBox(height: 20.0),
TextFormField(
controller: _phoneController,
decoration: const InputDecoration(
labelText: 'Número de Teléfono',
prefixIcon: Icon(Icons.phone_android_rounded),
hintText: '+57',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0),
),
),
),
const SizedBox(height: 20.0),
BirthdayPicker(
onDateSelected: (birthDay) {
_birthdayController.text =
DateFormat('dd/MM/yyyy').format(birthDay);
},
controller: _birthdayController,
),
const SizedBox(height: 20.0),
GenderDropdown(onChanged: (selectedGender) {
_genderController.text = selectedGender;
}),
const SizedBox(height: 60.0),
saveButton(state, context),
],
),
),
@@ -198,17 +206,16 @@ class _ProfileScreenState extends State<ProfileScreen> {
// Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue, // Color de fondo
backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), // Radio de borde
borderRadius: BorderRadius.circular(20),
),
shadowColor: Colors.grey, // Sombra
elevation: 5, // Elevación
shadowColor: Colors.grey,
elevation: 5,
),
child: Container(
constraints: const BoxConstraints(
maxWidth: 300.0, minHeight: 50.0), // Ajustes de tamaño
constraints: const BoxConstraints(maxWidth: 300.0, minHeight: 50.0),
alignment: Alignment.center,
child: isLoading
? const CircularProgressIndicator(
@@ -219,7 +226,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold, // Texto audaz
fontWeight: FontWeight.bold,
),
),
),