From 084d4b7a170f755858ecba854e657e92b5f439b4 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Fri, 30 May 2025 14:47:28 +0200 Subject: [PATCH] Added: login screen --- lib/main.dart | 13 ++++++ lib/screens/login.dart | 99 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 lib/screens/login.dart diff --git a/lib/main.dart b/lib/main.dart index f67f64a..b8509ae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'screens/add_screen.dart'; import 'screens/vehicles_screen.dart'; import 'screens/history_screen.dart'; import 'screens/user_settings.dart'; +import 'screens/login.dart'; void main() { runApp(FuelStatsApp()); @@ -17,6 +18,7 @@ class FuelStatsApp extends StatelessWidget { themeMode: ThemeMode.dark, debugShowCheckedModeBanner: false, home: MainNavigation(), + //home: LoginScreen(), ); } } @@ -30,6 +32,16 @@ class MainNavigation extends StatefulWidget { class _MainNavigationState extends State { int _currentIndex = 0; + bool loggedIn = false; + + @override + void initState() { + super.initState(); + + if(loggedIn == false) { + _currentIndex = 5; + } + } final List _screens = [ HomeScreen(), @@ -37,6 +49,7 @@ class _MainNavigationState extends State { VehiclesScreen(), HistoryScreen(), UserSettingsScreen(), + LoginScreen() ]; final List titles = [ diff --git a/lib/screens/login.dart b/lib/screens/login.dart new file mode 100644 index 0000000..5ed1a1c --- /dev/null +++ b/lib/screens/login.dart @@ -0,0 +1,99 @@ +import 'package:flutter/material.dart'; + +class LoginScreen extends StatefulWidget { + @override + State createState() => _LoginScreenState(); +} + +class _LoginScreenState extends State { + final _formKey = GlobalKey(); + 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), + ), + ), + ], + ), + ), + ), + ), + ), + ); + } +} +