Added: login screen
This commit is contained in:
		@@ -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<MainNavigation> {
 | 
			
		||||
  int _currentIndex = 0;
 | 
			
		||||
  bool loggedIn = false;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
 | 
			
		||||
    if(loggedIn == false) {
 | 
			
		||||
      _currentIndex = 5;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  final List<Widget> _screens = [
 | 
			
		||||
    HomeScreen(),
 | 
			
		||||
@@ -37,6 +49,7 @@ class _MainNavigationState extends State<MainNavigation> {
 | 
			
		||||
    VehiclesScreen(),
 | 
			
		||||
    HistoryScreen(),
 | 
			
		||||
    UserSettingsScreen(),
 | 
			
		||||
    LoginScreen()
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  final List<Widget> titles = [
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										99
									
								
								lib/screens/login.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								lib/screens/login.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
			
		||||
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),
 | 
			
		||||
                    ),
 | 
			
		||||
                  ),
 | 
			
		||||
                ],
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user