From f1005af7be5f1d19982de43cf449ff3e00f2e3f7 Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Tue, 3 Jun 2025 09:46:34 +0530 Subject: [PATCH 1/2] fix: Enhance login error handling with custom snackbar and update UI for beta environment --- lib/controller/auth/login_controller.dart | 40 +++++++++++++-------- lib/view/auth/login_screen.dart | 44 ++++++++++++++++++----- 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/lib/controller/auth/login_controller.dart b/lib/controller/auth/login_controller.dart index 7478bd4..3537759 100644 --- a/lib/controller/auth/login_controller.dart +++ b/lib/controller/auth/login_controller.dart @@ -4,6 +4,7 @@ import 'package:marco/controller/my_controller.dart'; import 'package:marco/helpers/services/auth_service.dart'; import 'package:marco/helpers/widgets/my_form_validator.dart'; import 'package:marco/helpers/widgets/my_validators.dart'; +import 'package:marco/helpers/widgets/my_snackbar.dart'; class LoginController extends MyController { // Form validator @@ -15,8 +16,8 @@ class LoginController extends MyController { final RxBool isChecked = false.obs; // Dummy credentials - final String _dummyEmail = "admin@marcoaiot.com"; - final String _dummyPassword = "User@123"; + final String _dummyEmail = ""; + final String _dummyPassword = ""; @override void onInit() { @@ -48,25 +49,34 @@ class LoginController extends MyController { } Future onLogin() async { - if (!basicValidator.validateForm()) return; + if (!basicValidator.validateForm()) return; - isLoading.value = true; + isLoading.value = true; - final errors = await AuthService.loginUser(basicValidator.getData()); + final errors = await AuthService.loginUser(basicValidator.getData()); - if (errors != null) { - basicValidator.addErrors(errors); - basicValidator.validateForm(); - basicValidator.clearErrors(); - } else { - final currentRoute = ModalRoute.of(Get.context!)?.settings.name ?? ""; - final nextUrl = Uri.parse(currentRoute).queryParameters['next'] ?? "/home"; - Get.toNamed(nextUrl); - } + if (errors != null) { + // Show custom snackbar using your utility + showAppSnackbar( + title: "Login Failed", + message: "Username or password is incorrect", + type: SnackbarType.error, + ); - isLoading.value = false; + // Handle validation display + basicValidator.addErrors(errors); + basicValidator.validateForm(); + basicValidator.clearErrors(); + } else { + final currentRoute = ModalRoute.of(Get.context!)?.settings.name ?? ""; + final nextUrl = Uri.parse(currentRoute).queryParameters['next'] ?? "/home"; + Get.toNamed(nextUrl); } + isLoading.value = false; +} + + void goToForgotPassword() { Get.toNamed('/auth/forgot_password'); } diff --git a/lib/view/auth/login_screen.dart b/lib/view/auth/login_screen.dart index 0c7f0e7..433e91a 100644 --- a/lib/view/auth/login_screen.dart +++ b/lib/view/auth/login_screen.dart @@ -11,6 +11,7 @@ import 'package:marco/helpers/widgets/my_text_style.dart'; import 'package:marco/view/layouts/auth_layout.dart'; import 'package:marco/images.dart'; import 'package:marco/view/auth/request_demo_bottom_sheet.dart'; +import 'package:marco/helpers/services/api_endpoints.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @@ -21,7 +22,7 @@ class LoginScreen extends StatefulWidget { class _LoginScreenState extends State with UIMixin { late final LoginController controller; - + bool get isBetaEnvironment => ApiEndpoints.baseUrl.contains("stage"); @override void initState() { controller = Get.put(LoginController(), tag: 'login_controller'); @@ -65,11 +66,37 @@ class _LoginScreenState extends State with UIMixin { ), ), MySpacing.height(20), - - /// Welcome - Center(child: MyText.bodyLarge("Welcome Back!", fontWeight: 600)), + /// Welcome + Beta + Center( + child: Column( + children: [ + if (isBetaEnvironment) + Container( + padding: const EdgeInsets.symmetric( + horizontal: 8, vertical: 4), + margin: const EdgeInsets.only(bottom: 12), + decoration: BoxDecoration( + color: Colors.blueAccent, + borderRadius: BorderRadius.circular(4), + ), + child: Text( + 'BETA', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 12, + ), + ), + ), + MyText.bodyLarge("Welcome Back!", fontWeight: 600), + ], + ), + ), MySpacing.height(4), - Center(child: MyText.bodySmall("Please sign in to continue.")), + Center( + child: MyText.bodySmall("Please sign in to continue."), + ), + MySpacing.height(20), /// Email @@ -113,8 +140,8 @@ class _LoginScreenState extends State with UIMixin { children: [ Obx(() { return InkWell( - onTap: () => - controller.onChangeCheckBox(!controller.isChecked.value), + onTap: () => controller.onChangeCheckBox( + !controller.isChecked.value), child: Row( children: [ Checkbox( @@ -130,8 +157,7 @@ class _LoginScreenState extends State with UIMixin { .contains(WidgetState.selected)) { return Colors.blueAccent; } - return Colors - .white; + return Colors.white; }, ), checkColor: contentTheme.onPrimary, -- 2.43.0 From 6fa8858d8791b4461a5d83f86d226c3c166d1841 Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Tue, 3 Jun 2025 11:05:21 +0530 Subject: [PATCH 2/2] fix: Update project selection logic to fetch task data instead of projects --- lib/view/taskPlaning/daily_progress.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/view/taskPlaning/daily_progress.dart b/lib/view/taskPlaning/daily_progress.dart index ba5cc4f..0c394d4 100644 --- a/lib/view/taskPlaning/daily_progress.dart +++ b/lib/view/taskPlaning/daily_progress.dart @@ -157,11 +157,7 @@ class _DailyProgressReportScreenState extends State if (selectedProjectId != null && selectedProjectId != dailyTaskController.selectedProjectId) { dailyTaskController.selectedProjectId = selectedProjectId; - try { - await dailyTaskController.fetchProjects(); - } catch (e) { - debugPrint('Error fetching projects: $e'); - } + await dailyTaskController.fetchTaskData(selectedProjectId); dailyTaskController.update(['daily_progress_report_controller']); } } -- 2.43.0