- Replaced instances of the Logger package with a custom appLogger for consistent logging. - Introduced app_logger.dart to manage logging with file output and storage permissions. - Updated all controllers (e.g., DashboardController, EmployeesScreenController, etc.) to use appLogger for logging messages. - Ensured that logging messages are appropriately categorized (info, warning, error) throughout the application. - Implemented a file logging mechanism to store logs in a designated directory. - Cleaned up old log files to maintain only the most recent logs.
104 lines
2.7 KiB
Dart
104 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/helpers/services/app_logger.dart';
|
|
import 'package:marco/helpers/services/api_service.dart';
|
|
import 'package:marco/helpers/theme/theme_customizer.dart';
|
|
import 'package:marco/model/project_model.dart';
|
|
|
|
|
|
|
|
class LayoutController extends GetxController {
|
|
// Theme Customization
|
|
ThemeCustomizer themeCustomizer = ThemeCustomizer();
|
|
|
|
// Global Keys
|
|
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
|
final GlobalKey<State<StatefulWidget>> scrollKey = GlobalKey();
|
|
|
|
// Scroll
|
|
final ScrollController scrollController = ScrollController();
|
|
|
|
// Reactive State
|
|
final RxBool isLoading = true.obs;
|
|
final RxBool isLoadingProjects = true.obs;
|
|
final RxBool isProjectSelectionExpanded = true.obs;
|
|
final RxBool isProjectListExpanded = false.obs;
|
|
final RxBool isProjectDropdownExpanded = false.obs;
|
|
final RxList<ProjectModel> projects = <ProjectModel>[].obs;
|
|
final RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
|
|
|
// Selected Project
|
|
RxString? selectedProjectId;
|
|
|
|
bool isLastIndex = false;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchProjects();
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
ThemeCustomizer.addListener(onChangeTheme);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
ThemeCustomizer.removeListener(onChangeTheme);
|
|
scrollController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
// Project Handling
|
|
Future<void> fetchProjects() async {
|
|
isLoading.value = true;
|
|
isLoadingProjects.value = true;
|
|
|
|
final response = await ApiService.getProjects();
|
|
|
|
if (response != null && response.isNotEmpty) {
|
|
final fetchedProjects = response.map((json) => ProjectModel.fromJson(json)).toList();
|
|
projects.assignAll(fetchedProjects);
|
|
selectedProjectId = RxString(fetchedProjects.first.id.toString());
|
|
appLogger.i("Projects fetched: ${fetchedProjects.length}");
|
|
} else {
|
|
appLogger.w("No projects found or API call failed.");
|
|
}
|
|
|
|
isLoadingProjects.value = false;
|
|
isLoading.value = false;
|
|
update(['dashboard_controller']);
|
|
}
|
|
|
|
void updateSelectedProject(String projectId) {
|
|
selectedProjectId?.value = projectId;
|
|
}
|
|
|
|
void toggleProjectListExpanded() {
|
|
isProjectListExpanded.toggle();
|
|
}
|
|
|
|
// Theme Updates
|
|
void onChangeTheme(ThemeCustomizer oldVal, ThemeCustomizer newVal) {
|
|
themeCustomizer = newVal;
|
|
update();
|
|
|
|
if (newVal.rightBarOpen) {
|
|
scaffoldKey.currentState?.openEndDrawer();
|
|
} else {
|
|
scaffoldKey.currentState?.closeEndDrawer();
|
|
}
|
|
}
|
|
|
|
// Notification Shade (placeholders)
|
|
void enableNotificationShade() {
|
|
// Add implementation if needed
|
|
}
|
|
|
|
void disableNotificationShade() {
|
|
// Add implementation if needed
|
|
}
|
|
}
|