2025-05-30 14:48:05 +02:00

100 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
class LoginScreen extends StatefulWidget {
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
void _login() {
if (_formKey.currentState!.validate()) {
final email = _emailController.text;
final password = _passwordController.text;
// TODO: Replace with actual login logic
print('Logging in with $email and $password');
if(email == "test@test.com" && password == "Test1234") {
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('User Login')),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Form(
key: _formKey,
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Log in to Fuel Stats',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 32),
TextFormField(
controller: _emailController,
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email),
border: OutlineInputBorder(),
),
keyboardType: TextInputType.emailAddress,
validator: (value) {
if (value == null || value.isEmpty)
return 'Please enter your email';
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value))
return 'Enter a valid email';
return null;
},
),
const SizedBox(height: 16),
TextFormField(
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: Icon(Icons.lock),
border: OutlineInputBorder(),
),
obscureText: true,
validator: (value) {
if (value == null || value.isEmpty)
return 'Please enter your password';
if (value.length < 6)
return 'Password must be at least 6 characters';
return null;
},
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: _login,
icon: Icon(Icons.login),
label: Text('Log In'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 12),
),
),
],
),
),
),
),
),
);
}
}