Initial commit: Eventify frontend

This commit is contained in:
Rishad7594
2026-01-31 15:23:18 +05:30
commit b41cf6cc58
193 changed files with 12401 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';
import '../models/user_model.dart';
import '../services/auth_service.dart';
class AuthProvider extends ChangeNotifier {
final AuthService _authService = AuthService();
UserModel? _user;
bool _loading = false;
UserModel? get user => _user;
bool get loading => _loading;
/// Login with username/email and password.
Future<void> login(String username, String password) async {
_loading = true;
notifyListeners();
try {
final user = await _authService.login(username, password);
_user = user;
} finally {
_loading = false;
notifyListeners();
}
}
/// Register wrapper that is compatible with both old and new callers.
///
/// Preferred: provide [email], [phoneNumber], [password].
/// Older callers that pass [username] will still work — username is ignored
/// for the backend call (we use email/phone/password as per API spec).
Future<void> register({
String? username, // kept for backward compatibility; not sent to backend
String? email,
required String password,
String? phoneNumber,
}) async {
_loading = true;
notifyListeners();
try {
// Prefer explicit email param; if not provided try to use username (some screens passed email as username)
final resolvedEmail = (email != null && email.isNotEmpty) ? email : (username ?? '');
// Ensure we always pass a string phoneNumber to the AuthService (it expects a non-null value)
final resolvedPhone = phoneNumber ?? '';
final user = await _authService.register(
email: resolvedEmail,
phoneNumber: resolvedPhone,
password: password,
);
_user = user;
} finally {
_loading = false;
notifyListeners();
}
}
Future<void> logout() async {
await _authService.logout();
_user = null;
notifyListeners();
}
}