import 'package:flutter/material.dart'; import '../services/auth_service.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key, required this.auth, required this.onLoggedIn}); final AuthService auth; final VoidCallback onLoggedIn; @override State createState() => _LoginScreenState(); } class _LoginScreenState extends State { bool _busy = false; String? _error; Future _login() async { setState(() { _busy = true; _error = null; }); try { if (await widget.auth.login()) { widget.onLoggedIn(); } else { setState(() => _error = 'Connexion annulée.'); } } catch (e) { setState(() => _error = 'Échec de la connexion : $e'); } finally { if (mounted) setState(() => _busy = false); } } @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; return Scaffold( body: Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [scheme.primary.withValues(alpha: 0.25), scheme.surface], ), ), child: SafeArea( child: Padding( padding: const EdgeInsets.all(28), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Icon(Icons.sports_esports, size: 72, color: scheme.primary), const SizedBox(height: 20), Text('GameManager', style: Theme.of(context).textTheme.displaySmall?.copyWith( fontWeight: FontWeight.w900, letterSpacing: -1)), const SizedBox(height: 6), Text('Pilote tes serveurs de jeu', style: TextStyle(fontSize: 16, color: scheme.onSurfaceVariant)), const SizedBox(height: 40), if (_error != null) ...[ Text(_error!, style: TextStyle(color: scheme.error)), const SizedBox(height: 16), ], SizedBox( width: double.infinity, child: FilledButton.icon( onPressed: _busy ? null : _login, icon: _busy ? const SizedBox( width: 18, height: 18, child: CircularProgressIndicator(strokeWidth: 2)) : const Icon(Icons.login), label: Text(_busy ? 'Connexion…' : 'Se connecter avec pocket-id'), ), ), ], ), ), ), ), ); } }