- Added DashboardController and ProjectController for managing project data. - Enhanced LayoutController to support project selection and loading states. - Created UserProfileBar for user-specific actions and information. - Refactored app initialization logic to streamline setup and error handling. - Updated layout views to integrate project selection and improve user experience.
55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:logger/logger.dart';
|
|
import 'package:marco/helpers/services/api_service.dart';
|
|
import 'package:marco/model/project_model.dart';
|
|
|
|
final Logger log = Logger();
|
|
|
|
class DashboardController extends GetxController {
|
|
RxList<ProjectModel> projects = <ProjectModel>[].obs;
|
|
RxString? selectedProjectId;
|
|
var isProjectListExpanded = false.obs;
|
|
RxBool isProjectSelectionExpanded = true.obs;
|
|
|
|
void toggleProjectListExpanded() {
|
|
isProjectListExpanded.value = !isProjectListExpanded.value;
|
|
}
|
|
|
|
var isProjectDropdownExpanded = false.obs;
|
|
|
|
RxBool isLoading = true.obs;
|
|
RxBool isLoadingProjects = true.obs;
|
|
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchProjects();
|
|
}
|
|
|
|
/// Fetches projects and initializes selected project.
|
|
Future<void> fetchProjects() async {
|
|
isLoadingProjects.value = true;
|
|
isLoading.value = true;
|
|
|
|
final response = await ApiService.getProjects();
|
|
|
|
if (response != null && response.isNotEmpty) {
|
|
projects.assignAll(
|
|
response.map((json) => ProjectModel.fromJson(json)).toList());
|
|
selectedProjectId = RxString(projects.first.id.toString());
|
|
log.i("Projects fetched: ${projects.length}");
|
|
} else {
|
|
log.w("No projects found or API call failed.");
|
|
}
|
|
|
|
isLoadingProjects.value = false;
|
|
isLoading.value = false;
|
|
update(['dashboard_controller']);
|
|
}
|
|
|
|
void updateSelectedProject(String projectId) {
|
|
selectedProjectId?.value = projectId;
|
|
}
|
|
}
|