Files
mcbeno-app/lib/screens/login_screen.dart
b3ni15 871bfcdccb feat: Initialize Flutter app with authentication and scheduling features
- Removed TypeScript configuration file (tsconfig.json).
- Added Flutter plugin dependencies for secure storage.
- Implemented main application structure with routing for login, profile, and schedule screens.
- Developed LoginScreen with authentication logic and user feedback.
- Created ProfileScreen to display user profile information and logout functionality.
- Built ScheduleScreen to show weekly work schedule with navigation controls.
- Integrated AuthService for handling authentication, token storage, and API interactions.
- Updated pubspec.yaml with necessary dependencies for the Flutter project.
2025-08-20 22:48:54 +02:00

59 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/auth_service.dart';
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _userCtrl = TextEditingController();
final _pwCtrl = TextEditingController();
bool _loading = false;
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthService>(context);
// Auto-redirect if already logged in
if (auth.token != null) {
Future.microtask(() => Navigator.pushReplacementNamed(context, '/profile'));
}
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Bejelentkezés', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
SizedBox(height: 16),
TextField(controller: _userCtrl, decoration: InputDecoration(labelText: 'Felhasználó')),
SizedBox(height: 8),
TextField(controller: _pwCtrl, decoration: InputDecoration(labelText: 'Jelszó'), obscureText: true),
SizedBox(height: 16),
ElevatedButton(
onPressed: _loading ? null : () async {
final username = _userCtrl.text.trim();
final password = _pwCtrl.text.trim();
if (username.isEmpty || password.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Kérlek add meg a felhasználónevet és jelszót')));
return;
}
setState(() { _loading = true; });
final ok = await auth.login(username, password);
setState(() { _loading = false; });
if (ok) Navigator.pushReplacementNamed(context, '/profile');
else ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Bejelentkezés sikertelen')));
},
child: _loading ? SizedBox(height: 16, width: 16, child: CircularProgressIndicator(strokeWidth: 2)) : Text('Bejelentkezés'),
)
],
),
),
),
);
}
}