feat(frontend): init Flutter project with login screen and JWT auth

- Projet Flutter créé manuellement (pubspec.yaml, structure lib/)
- Écran de connexion complet avec validation, gestion erreurs, spinner
- ApiClient Dio avec intercepteur JWT automatique
- AuthProvider (Provider) + AuthService (shared_preferences)
- Routing GoRouter avec redirection auth/non-auth
- DashboardScreen placeholder
- Rapport PFE : ajout Chapitre 5 Frontend (architecture, JWT, login)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-20 20:15:58 +01:00
co-authored by Claude Sonnet 4.6
parent 3816f8b8f1
commit c1dabb486d
9 changed files with 620 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import '../services/auth_service.dart';
class AuthProvider extends ChangeNotifier {
bool _isAuthenticated = false;
String? _role;
String? _errorMessage;
bool _isLoading = false;
bool get isAuthenticated => _isAuthenticated;
String? get role => _role;
String? get errorMessage => _errorMessage;
bool get isLoading => _isLoading;
Future<bool> login(String username, String password) async {
_isLoading = true;
_errorMessage = null;
notifyListeners();
try {
final data = await AuthService.login(username, password);
final token = data['token'] as String;
final roles = data['roles'] as List<dynamic>;
final role = roles.isNotEmpty ? roles.first as String : 'ROLE_USER';
await AuthService.saveToken(token, role);
_isAuthenticated = true;
_role = role;
return true;
} catch (e) {
_errorMessage = 'Identifiants incorrects. Vérifiez votre nom d\'utilisateur et mot de passe.';
return false;
} finally {
_isLoading = false;
notifyListeners();
}
}
Future<void> logout() async {
await AuthService.logout();
_isAuthenticated = false;
_role = null;
notifyListeners();
}
Future<void> checkAuth() async {
final token = await AuthService.getToken();
_isAuthenticated = token != null;
_role = await AuthService.getRole();
notifyListeners();
}
}