import 'package:flutter/material.dart'; import '/data/models/contact_model.dart'; import '/data/repositories/contact_repository.dart'; class ContactProvider extends ChangeNotifier { final ContactRepository _repository = ContactRepository(); List _contacts = []; List _allContacts = []; bool _isLoading = false; String? _error; int? _currentUserId; List get contacts => _contacts; List get allContacts => _allContacts; bool get isLoading => _isLoading; String? get error => _error; void setCurrentUserId(int? id) { _currentUserId = id; notifyListeners(); } Future loadContacts() async { _isLoading = true; _error = null; notifyListeners(); try { final allContacts = await _repository.fetchContacts(); // Фильтруем: исключаем себя (для основного списка - только чаты) _contacts = allContacts.where((contact) => contact.id != _currentUserId).toList(); _allContacts = _contacts; } catch (e) { _error = e.toString(); } finally { _isLoading = false; notifyListeners(); } } // Метод для получения всех контактов (исключая себя) для нового чата Future loadAllContactsForNewChat() async { _isLoading = true; _error = null; notifyListeners(); try { final allContacts = await _repository.fetchContacts(); // Фильтруем только исключение самого себя _allContacts = allContacts.where((contact) => contact.id != _currentUserId).toList(); } catch (e) { _error = e.toString(); } finally { _isLoading = false; notifyListeners(); } } }