Added: signup screen, routing logic for login,signup

This commit is contained in:
2025-06-03 12:23:30 +02:00
parent 084d4b7a17
commit 2a5782b297
3 changed files with 195 additions and 30 deletions

View File

@@ -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<MainNavigation> {
int _currentIndex = 0;
bool loggedIn = false;
bool get isAuthScreen => _currentIndex == 5 || _currentIndex == 6;
@override
void initState() {
@@ -43,15 +45,6 @@ class _MainNavigationState extends State<MainNavigation> {
}
}
final List<Widget> _screens = [
HomeScreen(),
AddScreen(),
VehiclesScreen(),
HistoryScreen(),
UserSettingsScreen(),
LoginScreen()
];
final List<Widget> titles = [
Text("Fuel Stats"),
Text("Add record"),
@@ -59,12 +52,55 @@ class _MainNavigationState extends State<MainNavigation> {
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<Widget> 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<MainNavigation> {
);
},
),
],
),
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,
);
}
}