Files
prosappweb/lib/providers/professional_provider.dart
Lizandro GuarnizoandClaude Sonnet 4.6 577c4737ae persist professional mode across page refreshes
isProModeActive was in-memory only — a browser refresh reset it to
false even when the URL was a professional route.

Fix: read/write 'isProModeActive' from SharedPreferences in
ProfessionalProvider (constructor, toggleProMode, setIsProModeActive,
logout). Also clear the flag in AuthProvider.isAuthenticated() when the
user's proState is not active, so a stale value can't trap a non-pro user
in professional mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-12 19:07:20 -05:00

87 lines
2.6 KiB
Dart

import 'package:flutter/widgets.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/local_storage.dart';
class ProfessionalProvider extends ChangeNotifier {
Profesional? profesional;
bool _isProModeActive = false;
final _api = ApiService.instance;
static const _kProModeKey = 'isProModeActive';
ProfessionalProvider() {
_isProModeActive = LocalStorage.prefs.getBool(_kProModeKey) ?? false;
}
bool get isProModeActive => _isProModeActive;
Future<Profesional> getProfessional(String uid) async {
try {
final data = await _api.get('/professionals/me');
profesional = Profesional.fromDocument(data as Map<String, dynamic>);
} catch (_) {
// Professional profile doesn't exist yet — return empty so the form shows blank
profesional = Profesional(
id: uid,
identification: '',
rethusCode: '',
rethusValidated: false,
address: '',
aditionalAddress: '',
profession: '',
ratePreferences: false,
rate: '',
locationPreferences: LocationPreferences.office,
bannerPicture: '',
identificationPicture: '',
certificatePicture: '',
latitude: 0,
longitude: 0,
specializations: [],
specializationsPictures: [],
schedules: Schedules.empty,
paymentMethods: PaymentMethodEntity.empty,
);
}
notifyListeners();
return profesional!;
}
// Fetches any professional by UUID or user_id via the public endpoint.
// Used by CalendarView to load the target professional (not the logged-in user).
Future<Profesional> getProfessionalById(String id) async {
try {
final data = await _api.get('/professionals/$id');
final prof = Profesional.fromDocument(data as Map<String, dynamic>);
notifyListeners();
return prof;
} catch (_) {
return Profesional.empty();
}
}
void logout() {
_isProModeActive = false;
LocalStorage.prefs.setBool(_kProModeKey, false);
notifyListeners();
}
void toggleProMode() {
_isProModeActive = !_isProModeActive;
LocalStorage.prefs.setBool(_kProModeKey, _isProModeActive);
notifyListeners();
}
void setIsProModeActive(bool value) {
_isProModeActive = value;
LocalStorage.prefs.setBool(_kProModeKey, value);
notifyListeners();
}
sendProfessionalToReview() {}
}