Files
prosappweb/lib/providers/professional_form_provider.dart
T
Lizandro GuarnizoandClaude Sonnet 4.6 4951f82621 fix: errores de compilación - rethusValidated requerido y refreshUser void
- professional_form_provider: agregar rethusValidated al constructor Profesional
- professional_provider: agregar rethusCode y rethusValidated al fallback del constructor
- profile_view: quitar await de refreshUser() que retorna void

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-27 18:40:28 -05:00

113 lines
4.3 KiB
Dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:prosapp_web_app/models/location_preferences.dart';
import 'package:prosapp_web_app/models/payment_method_entity.dart';
import 'package:prosapp_web_app/models/profesional.dart';
import 'package:prosapp_web_app/models/schedules.dart';
import 'package:prosapp_web_app/services/api_service.dart';
import 'package:prosapp_web_app/services/notifications_service.dart';
class ProfessionalFormProvider with ChangeNotifier {
Profesional? profesional;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
GlobalKey<FormState> profileFormKey = GlobalKey<FormState>();
final _api = ApiService.instance;
copyProfesionalWith({
String? id,
String? identification,
String? rethusCode,
String? address,
String? aditionalAddress,
String? profession,
bool ratePreferences = false,
String? rate,
LocationPreferences? locationPreferences,
String? bannerPicture,
String? identificationPicture,
String? certificatePicture,
double? latitude,
double? longitude,
List<String>? specializations,
List<String>? specializationsPictures,
Schedules? schedules,
PaymentMethodEntity? paymentMethods,
}) {
profesional = Profesional(
id: id ?? profesional!.id,
identification: identification ?? profesional!.identification,
rethusCode: rethusCode ?? profesional!.rethusCode,
rethusValidated: profesional!.rethusValidated,
address: address ?? profesional!.address,
aditionalAddress: aditionalAddress ?? profesional!.aditionalAddress,
profession: profession ?? profesional!.profession,
ratePreferences: ratePreferences,
rate: rate ?? profesional!.rate,
locationPreferences: locationPreferences ?? profesional!.locationPreferences,
bannerPicture: bannerPicture ?? profesional!.bannerPicture,
identificationPicture: identificationPicture ?? profesional!.identificationPicture,
certificatePicture: certificatePicture ?? profesional!.certificatePicture,
latitude: latitude ?? profesional!.latitude,
longitude: longitude ?? profesional!.longitude,
specializations: specializations ?? profesional!.specializations,
specializationsPictures: specializationsPictures ?? profesional!.specializationsPictures,
schedules: schedules ?? profesional!.schedules,
paymentMethods: paymentMethods ?? profesional!.paymentMethods,
);
notifyListeners();
}
bool _validForm() => formKey.currentState!.validate();
bool _validProfileForm() => profileFormKey.currentState!.validate();
setProfesional(Profesional p) {
profesional = p;
notifyListeners();
}
Future<bool> updateProfesionalInfo(String userId) async {
if (!_validForm()) return false;
await _api.patch('/professionals/me', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<bool> updateProfesionalProfileInfo(String userId) async {
if (!_validProfileForm()) return false;
await _api.patch('/professionals/me', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<bool> updateProfesionalProfileScheduleInfo(String userId) async {
await _api.patch('/professionals/me', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<Profesional> uploadPdfIdentification(Uint8List fileBytes, String userId) async {
final url = await _api.upload(fileBytes, '${userId}_cedula.pdf');
if (url != null) copyProfesionalWith(identificationPicture: url);
notifyListeners();
return profesional!;
}
Future<Profesional> uploadPdfCertificate(Uint8List fileBytes, String userId) async {
final url = await _api.upload(fileBytes, '${userId}_certificado.pdf');
if (url != null) copyProfesionalWith(certificatePicture: url);
notifyListeners();
return profesional!;
}
Future<Profesional> uploadPdfSpecializations(List<Uint8List> filesBytes, String userId) async {
List<String> urls = [];
for (int i = 0; i < filesBytes.length; i++) {
final url = await _api.upload(filesBytes[i], '${userId}_especializacion_$i.pdf');
if (url != null) urls.add(url);
}
copyProfesionalWith(specializationsPictures: urls);
notifyListeners();
return profesional!;
}
}