Files
prosappweb/lib/providers/profile_form_provider.dart
Lizandro GuarnizoandClaude Sonnet 4.6 60216fd0e3 feat: migrate Firebase → NestJS REST API backend
Replace all Firebase SDK (Auth, Firestore, Storage) with HTTP calls
to backend.prosapp.co/api/v1:

- New ApiService singleton (JWT token, GET/POST/PATCH/DELETE/upload)
- auth_provider: Firebase Auth → /auth/login, /auth/register, /auth/phone/*
- services_provider + calendar_services_provider → /services endpoints
- professional_provider + professionals_provider → /professional-info, /users/professionals
- profile_form_provider + professional_form_provider → /users/me, /storage/upload
- cities/professions/settings providers → /cities, /professions, /settings
- firebase_chat_repository → polling via /chats endpoints (3s interval)
- firebase_score_repository → polling via /comments endpoints (10s interval)
- professional_detail_provider → /users/:id + /professional-info/:id
- dashboard_view: Firestore.add → POST /services
- chat_view + rating_view: FirebaseAuth.uid → AuthProvider.user.id
- Models: Timestamp → String for createdAt fields
- google_fonts upgraded to ^8.1.0 (Dart 3.12 compat)
- Remove firebase_core, firebase_auth, cloud_firestore, firebase_storage from pubspec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 15:53:39 -05:00

84 lines
2.6 KiB
Dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:prosapp_web_app/models/pro_state.dart';
import 'package:prosapp_web_app/models/usuario.dart';
import 'package:prosapp_web_app/services/api_service.dart';
import 'package:prosapp_web_app/services/notifications_service.dart';
class ProfileFormProvider extends ChangeNotifier {
Usuario? user;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
final _api = ApiService.instance;
void copyUserWith({
String? id,
String? email,
String? phone,
String? name,
String? nickname,
String? city,
String? picture,
String? birthday,
String? gender,
ProState? proState,
String? token,
}) {
user = Usuario(
id: id ?? user!.id,
email: email ?? user!.email,
phone: phone ?? user!.phone,
name: name ?? user!.name,
nickname: nickname ?? user!.nickname,
city: city ?? user!.city,
picture: picture ?? user!.picture,
birthday: birthday ?? user!.birthday,
gender: gender ?? user!.gender,
proState: proState ?? user!.proState,
token: token ?? user!.token,
);
notifyListeners();
}
bool _validForm() => formKey.currentState!.validate();
Future<void> updateUserInfo() async {
if (!_validForm()) return;
await _api.patch('/users/me', user!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
}
Future<void> updateUserInfoNoValid() async {
await _api.patch('/users/me', user!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
}
Future<Usuario> uploadPicture(Uint8List bytes) async {
final url = await _api.upload(bytes, 'profile_${user!.id}.jpg');
if (url != null) copyUserWith(picture: url);
notifyListeners();
return user!;
}
Future<void> signUpWithPhoneNumber(String phoneNumber) async {
try {
await _api.post('/auth/phone/link/send', {'phone': phoneNumber});
NotificationsService.showSnackbar('Código enviado al número $phoneNumber');
} catch (e) {
NotificationsService.showSnackbar('Error al enviar código: $e');
}
}
Future<bool> linkPhoneNumberToExistingAccount(String phoneNumber, String code) async {
try {
await _api.post('/auth/phone/link/verify', {'phone': phoneNumber, 'code': code});
copyUserWith(phone: phoneNumber);
notifyListeners();
NotificationsService.showSnackbar('Número vinculado exitosamente');
return true;
} catch (e) {
NotificationsService.showSnackbar('Código de verificación inválido');
return false;
}
}
}