84 lines
2.4 KiB
Dart
84 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/date_symbol_data_local.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'routes/app_routes.dart';
|
|
|
|
// AUTH
|
|
import 'screens/auth/welcome_screen.dart';
|
|
import 'screens/auth/login_screen.dart';
|
|
import 'screens/auth/register_screen.dart';
|
|
import 'screens/auth/forgot_password_screen.dart';
|
|
|
|
// DASHBOARD
|
|
import 'screens/dashboard/user/dashboard_user.dart';
|
|
import 'screens/dashboard/admin/dashboard_admin.dart';
|
|
|
|
// PROFILE
|
|
import 'screens/dashboard/user/profile_user_screen.dart';
|
|
import 'screens/dashboard/admin/profile_admin_screen.dart';
|
|
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await initializeDateFormatting('id_ID', null);
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final isLogin = prefs.getBool('isLogin') ?? false;
|
|
final role = prefs.getString('role');
|
|
|
|
runApp(MyApp(isLogin: isLogin, role: role));
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
final bool isLogin;
|
|
final String? role;
|
|
|
|
const MyApp({
|
|
super.key,
|
|
required this.isLogin,
|
|
this.role,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
navigatorKey: navigatorKey,
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
locale: const Locale('id', 'ID'),
|
|
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
|
|
supportedLocales: const [
|
|
Locale('id', 'ID'),
|
|
Locale('en', 'US')
|
|
],
|
|
|
|
initialRoute: isLogin
|
|
? (role == 'admin' || role == 'super_admin'
|
|
? AppRoutes.dashboardAdmin
|
|
: AppRoutes.dashboardUser)
|
|
: AppRoutes.welcome,
|
|
|
|
routes: {
|
|
AppRoutes.welcome: (context) => const WelcomeScreen(),
|
|
AppRoutes.login: (context) => const LoginScreen(),
|
|
AppRoutes.register: (context) => const RegisterScreen(),
|
|
AppRoutes.forgotPassword: (context) => const ForgotPasswordScreen(),
|
|
|
|
AppRoutes.dashboardUser: (context) => const DashboardUser(),
|
|
AppRoutes.dashboardAdmin: (context) => const DashboardAdmin(),
|
|
|
|
AppRoutes.userProfile: (context) => const ProfileUserScreen(),
|
|
AppRoutes.adminProfile: (context) => const ProfileAdminScreen(),
|
|
},
|
|
);
|
|
}
|
|
}
|