85 lines
2.4 KiB
Dart
85 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../providers/auth_provider.dart';
|
|
import 'schedule_screen.dart';
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({super.key});
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
bool _isLoading = false;
|
|
|
|
void _login() async {
|
|
setState(() => _isLoading = true);
|
|
try {
|
|
await context.read<AuthProvider>().login();
|
|
if (mounted) {
|
|
Navigator.of(context).pushReplacement(
|
|
MaterialPageRoute(builder: (_) => const ScheduleScreen()),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Erreur de connexion'),
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() => _isLoading = false);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
'MyIce - Games',
|
|
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
|
|
color: Colors.indigo,
|
|
),
|
|
),
|
|
const SizedBox(height: 32),
|
|
if (_isLoading)
|
|
const CircularProgressIndicator()
|
|
else
|
|
ElevatedButton(
|
|
onPressed: _login,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.indigo,
|
|
foregroundColor: Colors.white,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 32,
|
|
vertical: 16,
|
|
),
|
|
),
|
|
child: const Text('Se connecter avec Infomaniak'),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Connectez-vous pour acceder aux evenements...',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|