ontimehaulers/lib/main.dart
2024-11-05 17:59:06 +05:30

101 lines
2.5 KiB
Dart

import 'package:auto_orientation/auto_orientation.dart';
import 'package:flutter/material.dart';
import 'package:ontime_haulers/screens/home_screen.dart';
import 'package:ontime_haulers/screens/quote_screen.dart';
import 'package:ontime_haulers/screens/track_screen.dart';
import 'package:ontime_haulers/screens/login_screen.dart';
import 'package:ontime_haulers/screens/setup_screen.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _selectedIndex = 0;
bool _isLoading = true;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
if (index == 1) {
AutoOrientation.landscapeRightMode();
} else {
AutoOrientation.portraitUpMode();
}
});
}
_setScreen() {
switch (_selectedIndex) {
case 0:
return HomeScreen(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
);
case 1:
return QuoteScreen(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
);
case 2:
return TrackScreen(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
);
case 3:
return LoginScreen(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
);
case 4:
return SetupScreen(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
);
default:
return HomeScreen(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
);
}
}
@override
void initState() {
super.initState();
// Simulate a loading delay
Future.delayed(const Duration(seconds: 7), () {
setState(() {
_isLoading = false;
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: _isLoading
? Scaffold(
backgroundColor: Colors.red,
body: Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('assets/ot.gif'),
fit: BoxFit.cover,
),
),
),
)
: _setScreen(),
);
}
}