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'; import 'package:flutter/material.dart';
class GenderDropdown extends StatefulWidget { 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 @override
State<GenderDropdown> createState() => _GenderDropdownState(); State<GenderDropdown> createState() => _GenderDropdownState();
} }
class _GenderDropdownState extends State<GenderDropdown> { class _GenderDropdownState extends State<GenderDropdown> {
String? selectedGender; late TextEditingController controller;
@override
void initState() {
super.initState();
controller = widget.controller;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -28,15 +34,14 @@ class _GenderDropdownState extends State<GenderDropdown> {
child: DropdownButtonHideUnderline( child: DropdownButtonHideUnderline(
child: DropdownButton<String>( child: DropdownButton<String>(
isExpanded: true, isExpanded: true,
value: selectedGender, value: controller.text,
hint: const Text( hint: const Text(
'Selecciona tu género', 'Selecciona tu género',
style: TextStyle(fontSize: 16.0), style: TextStyle(fontSize: 16.0),
), ),
onChanged: (String? newValue) { onChanged: (String? newValue) {
setState(() { setState(() {
selectedGender = newValue; controller.text = newValue!;
widget.onChanged(selectedGender!);
}); });
}, },
items: ['Masculino', 'Femenino', 'Otro'] items: ['Masculino', 'Femenino', 'Otro']
+23 -16
View File
@@ -1,5 +1,4 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@@ -24,6 +23,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
final TextEditingController _phoneController = TextEditingController(); final TextEditingController _phoneController = TextEditingController();
final TextEditingController _birthdayController = TextEditingController(); final TextEditingController _birthdayController = TextEditingController();
final TextEditingController _genderController = TextEditingController(); final TextEditingController _genderController = TextEditingController();
XFile? _imageFile; XFile? _imageFile;
bool isLoading = false; bool isLoading = false;
@@ -46,7 +46,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
isLoading = true; isLoading = true;
}); });
} else if (state is UpdateUserInfoSuccess) { } else if (state is UpdateUserInfoSuccess) {
// Snack bar
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Información actualizada'), content: Text('Información actualizada'),
)); ));
@@ -74,12 +73,16 @@ class _ProfileScreenState extends State<ProfileScreen> {
_nameController.text = state.user!.name ?? ''; _nameController.text = state.user!.name ?? '';
_emailController.text = state.user!.email ?? ''; _emailController.text = state.user!.email ?? '';
_phoneController.text = state.user!.phone ?? ''; _phoneController.text = state.user!.phone ?? '';
_birthdayController.text = state.user!.birthday ?? '';
_genderController.text = state.user!.gender ?? '';
return SingleChildScrollView( return SingleChildScrollView(
child: Padding( child: Padding(
padding: padding:
const EdgeInsets.symmetric(horizontal: 40, vertical: 20), const EdgeInsets.symmetric(horizontal: 40, vertical: 20),
child: Column( child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
pictureWidget(state, context), pictureWidget(state, context),
@@ -98,7 +101,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
borderSide: BorderSide(color: Colors.red), borderSide: BorderSide(color: Colors.red),
), ),
focusedErrorBorder: OutlineInputBorder( focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0), borderSide:
BorderSide(color: Colors.red, width: 2.0),
), ),
), ),
validator: (value) { validator: (value) {
@@ -123,7 +127,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
borderSide: BorderSide(color: Colors.red), borderSide: BorderSide(color: Colors.red),
), ),
focusedErrorBorder: OutlineInputBorder( focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0), borderSide:
BorderSide(color: Colors.red, width: 2.0),
), ),
), ),
), ),
@@ -142,7 +147,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
borderSide: BorderSide(color: Colors.red), borderSide: BorderSide(color: Colors.red),
), ),
focusedErrorBorder: OutlineInputBorder( focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0), borderSide:
BorderSide(color: Colors.red, width: 2.0),
), ),
), ),
), ),
@@ -155,13 +161,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
controller: _birthdayController, controller: _birthdayController,
), ),
const SizedBox(height: 20.0), const SizedBox(height: 20.0),
GenderDropdown(onChanged: (selectedGender) { GenderDropdown(
_genderController.text = selectedGender; controller: _genderController,
}), ),
const SizedBox(height: 60.0), const SizedBox(height: 60.0),
saveButton(state, context), saveButton(state, context),
], ],
), ),
],
),
), ),
); );
} else { } else {
@@ -198,17 +206,16 @@ class _ProfileScreenState extends State<ProfileScreen> {
// Navigator.pop(context); // Navigator.pop(context);
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue, // Color de fondo backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 15), padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), // Radio de borde borderRadius: BorderRadius.circular(20),
), ),
shadowColor: Colors.grey, // Sombra shadowColor: Colors.grey,
elevation: 5, // Elevación elevation: 5,
), ),
child: Container( child: Container(
constraints: const BoxConstraints( constraints: const BoxConstraints(maxWidth: 300.0, minHeight: 50.0),
maxWidth: 300.0, minHeight: 50.0), // Ajustes de tamaño
alignment: Alignment.center, alignment: Alignment.center,
child: isLoading child: isLoading
? const CircularProgressIndicator( ? const CircularProgressIndicator(
@@ -219,7 +226,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, // Texto audaz fontWeight: FontWeight.bold,
), ),
), ),
), ),