perfil profesional terminado
This commit is contained in:
@@ -175,6 +175,32 @@ class AuthenticationRepository extends GetxController {
|
||||
return address;
|
||||
}
|
||||
|
||||
Future<String> getUbicacion(String uid) async {
|
||||
String location = '';
|
||||
try {
|
||||
final snapshot =
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
location = data?['ubicacion'] ?? '';
|
||||
} catch (e) {
|
||||
print('Error getting address: $e');
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
Future<String> getOpcionalAddress(String uid) async {
|
||||
String opcional_location = '';
|
||||
try {
|
||||
final snapshot =
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
opcional_location = data?['opcional_address'] ?? '';
|
||||
} catch (e) {
|
||||
print('Error getting address: $e');
|
||||
}
|
||||
return opcional_location;
|
||||
}
|
||||
|
||||
Future<String> getPhoto(String uid) async {
|
||||
String photo = '';
|
||||
try {
|
||||
|
||||
@@ -63,8 +63,34 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
int _dayOfWeekToInt(String dayOfWeek) {
|
||||
switch (dayOfWeek) {
|
||||
case 'Lunes':
|
||||
return 1;
|
||||
case 'Martes':
|
||||
return 2;
|
||||
case 'Miercoles':
|
||||
return 3;
|
||||
case 'Jueves':
|
||||
return 4;
|
||||
case 'Viernes':
|
||||
return 5;
|
||||
case 'Sabado':
|
||||
return 6;
|
||||
case 'Domingo':
|
||||
return 7;
|
||||
default:
|
||||
throw ArgumentError('Invalid day of week: $dayOfWeek');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sortedHorarios = Map.fromEntries(
|
||||
widget.horarios.entries.toList()
|
||||
..sort(
|
||||
(a, b) => _dayOfWeekToInt(a.key).compareTo(_dayOfWeekToInt(b.key))),
|
||||
);
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: PopAppbar(
|
||||
@@ -82,7 +108,7 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
||||
height: 5,
|
||||
),
|
||||
Column(
|
||||
children: widget.horarios.entries.map<Widget>(
|
||||
children: sortedHorarios.entries.map<Widget>(
|
||||
(entry) {
|
||||
return SchedulePicker(
|
||||
name: entry.key,
|
||||
@@ -92,7 +118,7 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
||||
).toList(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 100, bottom: 30),
|
||||
padding: const EdgeInsets.only(top: 30, bottom: 30),
|
||||
child: PrimaryButtom(
|
||||
onPressed: () async {
|
||||
updateHorario().then((value) => Navigator.pushReplacement(
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/banner_photo.dart';
|
||||
import 'package:prosappco/src/components/drawer_professional.dart';
|
||||
@@ -25,6 +26,8 @@ class ProfilePro extends StatefulWidget {
|
||||
|
||||
class _ProfileProState extends State<ProfilePro> {
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
final TextEditingController _opcionalAddressController =
|
||||
TextEditingController();
|
||||
|
||||
File? image_portada;
|
||||
File? imagen_to_upload;
|
||||
@@ -35,6 +38,8 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
|
||||
var _photo = '...';
|
||||
var _direccion = '...';
|
||||
var _ubicacion = '...';
|
||||
var _opcionalAddress = '...';
|
||||
|
||||
Map<String, Schedule>? _horarios;
|
||||
|
||||
@@ -71,12 +76,77 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
_direccion = s;
|
||||
}));
|
||||
}
|
||||
if (_ubicacion == '...') {
|
||||
AuthenticationRepository.instance.getUbicacion(uid.toString()).then(
|
||||
(String s) => setState(
|
||||
() {
|
||||
_ubicacion = s;
|
||||
if (_ubicacion == 'ambos') {
|
||||
sitioValue = true;
|
||||
domicilioValue = true;
|
||||
} else if (_ubicacion == 'sitio') {
|
||||
sitioValue = true;
|
||||
} else if (_ubicacion == 'domicilio') {
|
||||
domicilioValue = true;
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_opcionalAddress == '...') {
|
||||
AuthenticationRepository.instance.getOpcionalAddress(uid.toString()).then(
|
||||
(String s) => setState(
|
||||
() {
|
||||
_opcionalAddress = s;
|
||||
|
||||
if (_opcionalAddress != '...') {
|
||||
_opcionalAddressController.text = _opcionalAddress;
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateInfo() async {
|
||||
if (_opcionalAddressController.text.isNotEmpty) {
|
||||
FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'opcional_address': _opcionalAddressController.text});
|
||||
}
|
||||
|
||||
if (domicilioValue && sitioValue) {
|
||||
FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'ubicacion': 'ambos'});
|
||||
} else if (domicilioValue) {
|
||||
FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'ubicacion': 'domicilio'});
|
||||
} else if (sitioValue) {
|
||||
FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'ubicacion': 'sitio'});
|
||||
} else {
|
||||
Get.snackbar(
|
||||
'Elige como vas a dar tu servicio',
|
||||
'Selecciona si tu servicio es a domicilio o en tu consultorio.',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.black.withOpacity(0.2),
|
||||
messageText: const Text(
|
||||
'Selecciona si tu servicio es a domicilio o en tu consultorio.',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (imagen_to_upload == null) {
|
||||
return;
|
||||
} else {
|
||||
final uploaded = await uploadImage(imagen_to_upload!);
|
||||
updateImage(photoTemp);
|
||||
@@ -85,6 +155,13 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
} catch (e) {
|
||||
print('Error al actualizar la imagen de perfil $e');
|
||||
}
|
||||
|
||||
Get.snackbar(
|
||||
'Información actualizada',
|
||||
'Su información a sido actualizada con exito.',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Future<void> updateImage(image) async {
|
||||
@@ -269,7 +346,7 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextFormField(
|
||||
// controller: _emailController,
|
||||
controller: _opcionalAddressController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Oficina / Piso / Conjunto'),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user