Merge pull request 'Vaibhav_Enhancement-#419' (#36) from Vaibhav_Enhancement-#419 into main

Reviewed-on: #36
This commit is contained in:
vaibhav.surve 2025-06-03 05:36:00 +00:00
commit 2becfc603a
3 changed files with 61 additions and 29 deletions

View File

@ -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<void> 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');
}

View File

@ -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<LoginScreen> 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<LoginScreen> 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<LoginScreen> 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<LoginScreen> with UIMixin {
.contains(WidgetState.selected)) {
return Colors.blueAccent;
}
return Colors
.white;
return Colors.white;
},
),
checkColor: contentTheme.onPrimary,

View File

@ -157,11 +157,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
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']);
}
}