Vaibhav_Enhancement-#419 #36
@ -4,6 +4,7 @@ import 'package:marco/controller/my_controller.dart';
|
|||||||
import 'package:marco/helpers/services/auth_service.dart';
|
import 'package:marco/helpers/services/auth_service.dart';
|
||||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||||
import 'package:marco/helpers/widgets/my_validators.dart';
|
import 'package:marco/helpers/widgets/my_validators.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
|
|
||||||
class LoginController extends MyController {
|
class LoginController extends MyController {
|
||||||
// Form validator
|
// Form validator
|
||||||
@ -15,8 +16,8 @@ class LoginController extends MyController {
|
|||||||
final RxBool isChecked = false.obs;
|
final RxBool isChecked = false.obs;
|
||||||
|
|
||||||
// Dummy credentials
|
// Dummy credentials
|
||||||
final String _dummyEmail = "admin@marcoaiot.com";
|
final String _dummyEmail = "";
|
||||||
final String _dummyPassword = "User@123";
|
final String _dummyPassword = "";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -48,25 +49,34 @@ class LoginController extends MyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onLogin() async {
|
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) {
|
if (errors != null) {
|
||||||
basicValidator.addErrors(errors);
|
// Show custom snackbar using your utility
|
||||||
basicValidator.validateForm();
|
showAppSnackbar(
|
||||||
basicValidator.clearErrors();
|
title: "Login Failed",
|
||||||
} else {
|
message: "Username or password is incorrect",
|
||||||
final currentRoute = ModalRoute.of(Get.context!)?.settings.name ?? "";
|
type: SnackbarType.error,
|
||||||
final nextUrl = Uri.parse(currentRoute).queryParameters['next'] ?? "/home";
|
);
|
||||||
Get.toNamed(nextUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
void goToForgotPassword() {
|
||||||
Get.toNamed('/auth/forgot_password');
|
Get.toNamed('/auth/forgot_password');
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import 'package:marco/helpers/widgets/my_text_style.dart';
|
|||||||
import 'package:marco/view/layouts/auth_layout.dart';
|
import 'package:marco/view/layouts/auth_layout.dart';
|
||||||
import 'package:marco/images.dart';
|
import 'package:marco/images.dart';
|
||||||
import 'package:marco/view/auth/request_demo_bottom_sheet.dart';
|
import 'package:marco/view/auth/request_demo_bottom_sheet.dart';
|
||||||
|
import 'package:marco/helpers/services/api_endpoints.dart';
|
||||||
|
|
||||||
class LoginScreen extends StatefulWidget {
|
class LoginScreen extends StatefulWidget {
|
||||||
const LoginScreen({super.key});
|
const LoginScreen({super.key});
|
||||||
@ -21,7 +22,7 @@ class LoginScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _LoginScreenState extends State<LoginScreen> with UIMixin {
|
class _LoginScreenState extends State<LoginScreen> with UIMixin {
|
||||||
late final LoginController controller;
|
late final LoginController controller;
|
||||||
|
bool get isBetaEnvironment => ApiEndpoints.baseUrl.contains("stage");
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
controller = Get.put(LoginController(), tag: 'login_controller');
|
controller = Get.put(LoginController(), tag: 'login_controller');
|
||||||
@ -65,11 +66,37 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
MySpacing.height(20),
|
MySpacing.height(20),
|
||||||
|
/// Welcome + Beta
|
||||||
/// Welcome
|
Center(
|
||||||
Center(child: MyText.bodyLarge("Welcome Back!", fontWeight: 600)),
|
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),
|
MySpacing.height(4),
|
||||||
Center(child: MyText.bodySmall("Please sign in to continue.")),
|
Center(
|
||||||
|
child: MyText.bodySmall("Please sign in to continue."),
|
||||||
|
),
|
||||||
|
|
||||||
MySpacing.height(20),
|
MySpacing.height(20),
|
||||||
|
|
||||||
/// Email
|
/// Email
|
||||||
@ -113,8 +140,8 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
|
|||||||
children: [
|
children: [
|
||||||
Obx(() {
|
Obx(() {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () =>
|
onTap: () => controller.onChangeCheckBox(
|
||||||
controller.onChangeCheckBox(!controller.isChecked.value),
|
!controller.isChecked.value),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Checkbox(
|
Checkbox(
|
||||||
@ -130,8 +157,7 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
|
|||||||
.contains(WidgetState.selected)) {
|
.contains(WidgetState.selected)) {
|
||||||
return Colors.blueAccent;
|
return Colors.blueAccent;
|
||||||
}
|
}
|
||||||
return Colors
|
return Colors.white;
|
||||||
.white;
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
checkColor: contentTheme.onPrimary,
|
checkColor: contentTheme.onPrimary,
|
||||||
|
@ -157,11 +157,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
|||||||
if (selectedProjectId != null &&
|
if (selectedProjectId != null &&
|
||||||
selectedProjectId != dailyTaskController.selectedProjectId) {
|
selectedProjectId != dailyTaskController.selectedProjectId) {
|
||||||
dailyTaskController.selectedProjectId = selectedProjectId;
|
dailyTaskController.selectedProjectId = selectedProjectId;
|
||||||
try {
|
await dailyTaskController.fetchTaskData(selectedProjectId);
|
||||||
await dailyTaskController.fetchProjects();
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error fetching projects: $e');
|
|
||||||
}
|
|
||||||
dailyTaskController.update(['daily_progress_report_controller']);
|
dailyTaskController.update(['daily_progress_report_controller']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user