- Updated Android Gradle plugin version to 8.2.1 - Added new entries to .gitignore for better file management - Changed dummy email and password in LoginController for testing - Updated AuthService to handle login via API with improved error handling - Modified User model to use username instead of email - Enhanced login screen UI with better structure and design - Registered new plugins in GeneratedPluginRegistrant.swift - Updated package versions in pubspec.yaml and pubspec.lock
60 lines
1.8 KiB
Dart
60 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
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';
|
|
|
|
class LoginController extends MyController {
|
|
MyFormValidator basicValidator = MyFormValidator();
|
|
|
|
bool showPassword = false, isChecked = false;
|
|
|
|
final String _dummyEmail = "admin@marcobms.com";
|
|
final String _dummyPassword = "User@123";
|
|
|
|
@override
|
|
void onInit() {
|
|
basicValidator.addField('username', required: true, label: "User_Name", validators: [MyEmailValidator()], controller: TextEditingController(text: _dummyEmail));
|
|
|
|
basicValidator.addField('password',
|
|
required: true, label: "Password", validators: [MyLengthValidator(min: 6, max: 10)], controller: TextEditingController(text: _dummyPassword));
|
|
|
|
super.onInit();
|
|
}
|
|
|
|
void onChangeCheckBox(bool? value) {
|
|
isChecked = value ?? isChecked;
|
|
update();
|
|
}
|
|
|
|
void onChangeShowPassword() {
|
|
showPassword = !showPassword;
|
|
update();
|
|
}
|
|
|
|
Future<void> onLogin() async {
|
|
if (basicValidator.validateForm()) {
|
|
update();
|
|
var errors = await AuthService.loginUser(basicValidator.getData());
|
|
if (errors != null) {
|
|
basicValidator.addErrors(errors);
|
|
basicValidator.validateForm();
|
|
basicValidator.clearErrors();
|
|
} else {
|
|
String nextUrl = Uri.parse(ModalRoute.of(Get.context!)?.settings.name ?? "").queryParameters['next'] ?? "/home";
|
|
Get.toNamed(nextUrl);
|
|
}
|
|
update();
|
|
}
|
|
}
|
|
|
|
void goToForgotPassword() {
|
|
Get.toNamed('/auth/forgot_password');
|
|
}
|
|
|
|
void gotoRegister() {
|
|
Get.offAndToNamed('/auth/register_account');
|
|
}
|
|
}
|