Vaibhav_Feature-#768 #59
@ -8,41 +8,53 @@ import 'package:marco/helpers/theme/app_theme.dart';
|
|||||||
import 'package:url_strategy/url_strategy.dart';
|
import 'package:url_strategy/url_strategy.dart';
|
||||||
import 'package:marco/helpers/services/app_logger.dart';
|
import 'package:marco/helpers/services/app_logger.dart';
|
||||||
import 'package:marco/helpers/services/auth_service.dart';
|
import 'package:marco/helpers/services/auth_service.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
Future<void> initializeApp() async {
|
Future<void> initializeApp() async {
|
||||||
try {
|
try {
|
||||||
logSafe("💡 Starting app initialization...");
|
logSafe("💡 Starting app initialization...");
|
||||||
|
|
||||||
|
// UI Setup
|
||||||
setPathUrlStrategy();
|
setPathUrlStrategy();
|
||||||
logSafe("💡 URL strategy set.");
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
|
const SystemUiOverlayStyle(
|
||||||
statusBarColor: Color.fromARGB(255, 255, 0, 0),
|
statusBarColor: Colors.transparent,
|
||||||
|
systemNavigationBarColor: Colors.transparent,
|
||||||
statusBarIconBrightness: Brightness.light,
|
statusBarIconBrightness: Brightness.light,
|
||||||
));
|
systemNavigationBarIconBrightness: Brightness.dark,
|
||||||
logSafe("💡 System UI overlay style set.");
|
),
|
||||||
|
);
|
||||||
|
logSafe("💡 UI setup completed.");
|
||||||
|
|
||||||
|
// Local storage
|
||||||
await LocalStorage.init();
|
await LocalStorage.init();
|
||||||
logSafe("💡 Local storage initialized.");
|
logSafe("💡 Local storage initialized.");
|
||||||
|
|
||||||
// If a refresh token is found, try to refresh the JWT token
|
// Token handling
|
||||||
final refreshToken = await LocalStorage.getRefreshToken();
|
final refreshToken = await LocalStorage.getRefreshToken();
|
||||||
if (refreshToken != null && refreshToken.isNotEmpty) {
|
final hasRefreshToken = refreshToken?.isNotEmpty ?? false;
|
||||||
|
|
||||||
|
if (hasRefreshToken) {
|
||||||
logSafe("🔁 Refresh token found. Attempting to refresh JWT...");
|
logSafe("🔁 Refresh token found. Attempting to refresh JWT...");
|
||||||
final success = await AuthService.refreshToken();
|
final success = await AuthService.refreshToken();
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
logSafe("⚠️ Refresh token invalid or expired. Skipping controller injection.");
|
logSafe("⚠️ Refresh token invalid or expired. Skipping controller injection.");
|
||||||
// Optionally, clear tokens and force logout here if needed
|
// Optionally clear tokens or handle logout here
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logSafe("❌ No refresh token found. Skipping refresh.");
|
logSafe("❌ No refresh token found. Skipping refresh.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Theme setup
|
||||||
await ThemeCustomizer.init();
|
await ThemeCustomizer.init();
|
||||||
logSafe("💡 Theme customizer initialized.");
|
logSafe("💡 Theme customizer initialized.");
|
||||||
|
|
||||||
|
// Controller setup
|
||||||
final token = LocalStorage.getString('jwt_token');
|
final token = LocalStorage.getString('jwt_token');
|
||||||
if (token != null && token.isNotEmpty) {
|
final hasJwt = token?.isNotEmpty ?? false;
|
||||||
|
|
||||||
|
if (hasJwt) {
|
||||||
if (!Get.isRegistered<PermissionController>()) {
|
if (!Get.isRegistered<PermissionController>()) {
|
||||||
Get.put(PermissionController());
|
Get.put(PermissionController());
|
||||||
logSafe("💡 PermissionController injected.");
|
logSafe("💡 PermissionController injected.");
|
||||||
@ -53,13 +65,13 @@ Future<void> initializeApp() async {
|
|||||||
logSafe("💡 ProjectController injected as permanent.");
|
logSafe("💡 ProjectController injected as permanent.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load data into controllers if required
|
await Get.find<PermissionController>().loadData(token!);
|
||||||
await Get.find<PermissionController>().loadData(token);
|
|
||||||
await Get.find<ProjectController>().fetchProjects();
|
await Get.find<ProjectController>().fetchProjects();
|
||||||
} else {
|
} else {
|
||||||
logSafe("⚠️ No valid JWT token found. Skipping controller initialization.");
|
logSafe("⚠️ No valid JWT token found. Skipping controller initialization.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Final style setup
|
||||||
AppStyle.init();
|
AppStyle.init();
|
||||||
logSafe("💡 AppStyle initialized.");
|
logSafe("💡 AppStyle initialized.");
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ class _MainWrapperState extends State<MainWrapper> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
_initializeConnectivity();
|
_initializeConnectivity();
|
||||||
// Listen for changes, the callback now provides a List<ConnectivityResult>
|
// Listen for changes, the callback now provides a List<ConnectivityResult>
|
||||||
_connectivity.onConnectivityChanged.listen((List<ConnectivityResult> results) {
|
_connectivity.onConnectivityChanged
|
||||||
|
.listen((List<ConnectivityResult> results) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_connectivityStatus = results;
|
_connectivityStatus = results;
|
||||||
});
|
});
|
||||||
@ -84,7 +85,8 @@ class _MainWrapperState extends State<MainWrapper> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Check if any of the connectivity results indicate no internet
|
// Check if any of the connectivity results indicate no internet
|
||||||
final bool isOffline = _connectivityStatus.contains(ConnectivityResult.none);
|
final bool isOffline =
|
||||||
|
_connectivityStatus.contains(ConnectivityResult.none);
|
||||||
|
|
||||||
// Show OfflineScreen if no internet
|
// Show OfflineScreen if no internet
|
||||||
if (isOffline) {
|
if (isOffline) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user