import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:f0ckapp/controller/auth_controller.dart'; class LoginPage extends StatefulWidget { const LoginPage({super.key}); @override State createState() => _LoginPageState(); } class _LoginPageState extends State { final AuthController authController = Get.find(); final TextEditingController usernameController = TextEditingController(); final TextEditingController passwordController = TextEditingController(); bool _isLoading = false; void _showMsg(String message, {String title = ''}) { Get ..closeAllSnackbars() ..snackbar(message, title, snackPosition: SnackPosition.BOTTOM); } @override void dispose() { usernameController.dispose(); passwordController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: SingleChildScrollView( padding: const EdgeInsets.all(24), child: Card( elevation: 8, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), child: Padding( padding: const EdgeInsets.all(24), child: Column( mainAxisSize: MainAxisSize.min, children: [ Row( children: [ IconButton( icon: const Icon(Icons.arrow_back), tooltip: 'Zurück', onPressed: () => Get.back(), ), const SizedBox(width: 8), Text( 'Login', style: Theme.of(context).textTheme.headlineMedium, ), ], ), const SizedBox(height: 24), TextField( controller: usernameController, decoration: const InputDecoration( labelText: 'Benutzername', prefixIcon: Icon(Icons.person), border: OutlineInputBorder(), ), ), const SizedBox(height: 16), TextField( controller: passwordController, obscureText: true, decoration: const InputDecoration( labelText: 'Passwort', prefixIcon: Icon(Icons.lock), border: OutlineInputBorder(), ), ), const SizedBox(height: 24), SizedBox( width: double.infinity, child: ElevatedButton( onPressed: _isLoading ? null : () async { setState(() => _isLoading = true); final success = await authController.login( usernameController.text, passwordController.text, ); setState(() => _isLoading = false); if (!success) { return _showMsg('Login fehlgeschlagen!'); } _showMsg('Erfolgreich eingeloggt.'); Get.back(); }, child: _isLoading ? const SizedBox( width: 24, height: 24, child: CircularProgressIndicator( strokeWidth: 2, color: Colors.white, ), ) : const Text('Login'), ), ), ], ), ), ), ), ), ); } }