24 lines
864 B
Dart
24 lines
864 B
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
/// Consultórios marcados como favoritos, guardados localmente (por
|
|
/// [Clinic.id]) — mesmo padrão simples de outros `*Prefs` da app
|
|
/// (ex.: [WatchedVideosPrefs]), sem conta/servidor.
|
|
class ClinicFavoritesPrefs {
|
|
const ClinicFavoritesPrefs._();
|
|
|
|
static const String _kKey = 'favorite_clinic_ids';
|
|
|
|
static Future<Set<String>> getFavoriteIds() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return (prefs.getStringList(_kKey) ?? const []).toSet();
|
|
}
|
|
|
|
static Future<Set<String>> toggleFavorite(String clinicId) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final ids = (prefs.getStringList(_kKey) ?? const []).toSet();
|
|
if (!ids.add(clinicId)) ids.remove(clinicId);
|
|
await prefs.setStringList(_kKey, ids.toList());
|
|
return ids;
|
|
}
|
|
}
|