diff --git a/lib/main.dart b/lib/main.dart index b8509ae..a034cae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'screens/vehicles_screen.dart'; import 'screens/history_screen.dart'; import 'screens/user_settings.dart'; import 'screens/login.dart'; +import 'screens/signup.dart'; void main() { runApp(FuelStatsApp()); @@ -33,6 +34,7 @@ class MainNavigation extends StatefulWidget { class _MainNavigationState extends State { int _currentIndex = 0; bool loggedIn = false; + bool get isAuthScreen => _currentIndex == 5 || _currentIndex == 6; @override void initState() { @@ -43,15 +45,6 @@ class _MainNavigationState extends State { } } - final List _screens = [ - HomeScreen(), - AddScreen(), - VehiclesScreen(), - HistoryScreen(), - UserSettingsScreen(), - LoginScreen() - ]; - final List titles = [ Text("Fuel Stats"), Text("Add record"), @@ -59,12 +52,55 @@ class _MainNavigationState extends State { Text("History"), ]; + Widget get currentTitle { + switch (_currentIndex) { + case 0: + return Text("Fuel Stats"); + case 1: + return Text("Add record"); + case 2: + return Text("Vehicles"); + case 3: + return Text("History"); + case 4: + return Text("Settings"); + case 5: + return Text("Login"); + case 6: + return Text("Sign up"); + default: + return Text("Fuel Stats"); + } +} + @override Widget build(BuildContext context) { + List screens = [ + HomeScreen(), + AddScreen(), + VehiclesScreen(), + HistoryScreen(), + UserSettingsScreen(), + LoginScreen( + onSwitchToSignup: () { + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() => _currentIndex = 6); + }); + }, + ), + SignupScreen( + onSwitchToLogin: () { + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() => _currentIndex = 5); + }); + }, + ), + ]; + return Scaffold( appBar: AppBar( - title: _currentIndex <= 3 ? titles[_currentIndex] : Text("Fuel Stats"), - actions: [ + title: currentTitle, + actions: !isAuthScreen ? [ IconButton( icon: const Icon(Icons.person), tooltip: "User settings", @@ -75,25 +111,26 @@ class _MainNavigationState extends State { ); }, ), - ], - ), - body: _screens[_currentIndex], - bottomNavigationBar: BottomNavigationBar( - currentIndex: _currentIndex <= 3 ? _currentIndex : 0, - onTap: (index) => setState(() => _currentIndex = index), - backgroundColor: Colors.grey[900], - selectedItemColor: Colors.white, - unselectedItemColor: Colors.grey, - items: const [ - BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'), - BottomNavigationBarItem(icon: Icon(Icons.add), label: 'Add'), - BottomNavigationBarItem( - icon: Icon(Icons.directions_car), - label: 'Vehicles', - ), - BottomNavigationBarItem(icon: Icon(Icons.history), label: 'History'), - ], + ] : null, ), + body: screens[_currentIndex], + bottomNavigationBar: !isAuthScreen ? + BottomNavigationBar( + currentIndex: _currentIndex <= 3 ? _currentIndex : 0, + onTap: (index) => setState(() => _currentIndex = index), + backgroundColor: Colors.grey[900], + selectedItemColor: Colors.white, + unselectedItemColor: Colors.grey, + items: const [ + BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'), + BottomNavigationBarItem(icon: Icon(Icons.add), label: 'Add'), + BottomNavigationBarItem( + icon: Icon(Icons.directions_car), + label: 'Vehicles', + ), + BottomNavigationBarItem(icon: Icon(Icons.history), label: 'History'), + ], + ) : null, ); } } diff --git a/lib/screens/login.dart b/lib/screens/login.dart index 5ed1a1c..6be6fda 100644 --- a/lib/screens/login.dart +++ b/lib/screens/login.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; +import 'signup.dart'; class LoginScreen extends StatefulWidget { + final VoidCallback onSwitchToSignup; + const LoginScreen({required this.onSwitchToSignup, super.key}); + @override State createState() => _LoginScreenState(); } @@ -25,7 +29,7 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text('User Login')), + //appBar: AppBar(title: Text('User Login')), body: Padding( padding: const EdgeInsets.all(24.0), child: Form( @@ -87,6 +91,11 @@ class _LoginScreenState extends State { padding: EdgeInsets.symmetric(horizontal: 32, vertical: 12), ), ), + const SizedBox(height: 12), + TextButton( + onPressed: widget.onSwitchToSignup, + child: Text("Don't have an account? Sign up"), + ), ], ), ), diff --git a/lib/screens/signup.dart b/lib/screens/signup.dart new file mode 100644 index 0000000..ff77a69 --- /dev/null +++ b/lib/screens/signup.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; + +class SignupScreen extends StatefulWidget { + final VoidCallback onSwitchToLogin; + const SignupScreen({required this.onSwitchToLogin, super.key}); + + @override + State createState() => _SignupScreenState(); +} + +class _SignupScreenState extends State { + final _formKey = GlobalKey(); + final _usernameController = TextEditingController(); + final _emailController = TextEditingController(); + final _passwordController = TextEditingController(); + + void _signup() { + if (_formKey.currentState!.validate()) { + final username = _usernameController.text; + final email = _emailController.text; + final password = _passwordController.text; + // TODO: Replace with actual signup logic + print('Signing up with $username, $email, $password'); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + //appBar: AppBar(title: Text('Sign Up')), + body: Padding( + padding: const EdgeInsets.all(24.0), + child: Form( + key: _formKey, + child: Center( + child: SingleChildScrollView( + child: Column( + children: [ + Text( + 'Create your Fuel Stats account', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 32), + TextFormField( + controller: _usernameController, + decoration: InputDecoration( + labelText: 'Username', + prefixIcon: Icon(Icons.person), + border: OutlineInputBorder(), + ), + validator: (value) { + if (value == null || value.isEmpty) + return 'Please enter a username'; + return null; + }, + ), + const SizedBox(height: 16), + 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 an 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 a password'; + if (value.length < 6) + return 'Password must be at least 6 characters'; + return null; + }, + ), + const SizedBox(height: 24), + ElevatedButton.icon( + onPressed: _signup, + icon: Icon(Icons.person_add), + label: Text('Sign Up'), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.blue, + foregroundColor: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 32, vertical: 12), + ), + ), + const SizedBox(height: 12), + TextButton( + onPressed: widget.onSwitchToLogin, + child: Text("Already have an account? Log in"), + ), + ], + ), + ), + ), + ), + ), + ); + } +} +