207 lines
8.3 KiB
Dart
207 lines
8.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import '../../widgets/comman_text_from_filed.dart';
|
|
import '../../widgets/custom_button.dart';
|
|
import 'controller/auth_controller.dart';
|
|
import 'forget_password_screen.dart';
|
|
// Make sure you import HomeScreen
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({super.key});
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
final formKey = GlobalKey<FormState>();
|
|
final authController = Get.put(AuthController());
|
|
final String emailPattern = r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$';
|
|
final String passwordPattern = r'^.{6,}$'; // At least 6 characters
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Stack(
|
|
alignment: Alignment.topCenter,
|
|
children: [
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
fit: BoxFit.cover,
|
|
image: AssetImage('assets/images/image_1.png'),
|
|
),
|
|
borderRadius: BorderRadius.only(
|
|
bottomLeft: Radius.circular(50.0),
|
|
bottomRight: Radius.circular(50.0),
|
|
),
|
|
),
|
|
child: SizedBox(
|
|
width: Get.width,
|
|
height: Get.height * 0.7,
|
|
),
|
|
),
|
|
SingleChildScrollView(
|
|
child: Form(
|
|
key: formKey,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(height: Get.height * 0.1),
|
|
Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 20),
|
|
child: Text(
|
|
'Welcome',
|
|
style: GoogleFonts.getFont(
|
|
'Roboto',
|
|
fontWeight: FontWeight.w400,
|
|
fontSize: 24,
|
|
height: 1.5,
|
|
color: const Color(0xFFFFFFFF),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFFFFFFF),
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: Container(
|
|
width: Get.width * 0.7,
|
|
height: Get.height * 0.07,
|
|
padding: const EdgeInsets.all(10),
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
fit: BoxFit.fill,
|
|
image: AssetImage(
|
|
'assets/images/px_cheminova_svg.png',
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: Get.height * 0.05),
|
|
Card(
|
|
margin: const EdgeInsets.symmetric(horizontal: 24),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(19),
|
|
side: const BorderSide(color: Color(0xFFFDFDFD)),
|
|
),
|
|
color: const Color(0xFFB4D1E5).withOpacity(0.9),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
alignment: Alignment.centerLeft,
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: SvgPicture.asset(
|
|
'assets/svg/login.svg',
|
|
height: Get.height * 0.05,
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'Login',
|
|
style: GoogleFonts.getFont(
|
|
'Roboto',
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 30,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'Sign in to Continue',
|
|
style: GoogleFonts.getFont(
|
|
'Roboto',
|
|
fontWeight: FontWeight.w300,
|
|
fontSize: 14,
|
|
height: 1.8,
|
|
),
|
|
),
|
|
),
|
|
CommonTextFormField(
|
|
controller: authController.emailController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Please enter your email id';
|
|
}
|
|
if (!RegExp(emailPattern).hasMatch(value)) {
|
|
return 'Please Enter valid email';
|
|
}
|
|
return null;
|
|
},
|
|
title: 'Email',
|
|
label: "Email",
|
|
),
|
|
const SizedBox(height: 15),
|
|
CommonTextFormField(
|
|
controller: authController.passwordController,
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Please enter your password';
|
|
}
|
|
if (!RegExp(passwordPattern).hasMatch(value)) {
|
|
return 'Please Enter valid password';
|
|
}
|
|
return null;
|
|
},
|
|
obscureText: true,
|
|
title: 'Password',
|
|
maxLines: 1,
|
|
label: "Password",
|
|
),
|
|
const SizedBox(height: 30),
|
|
GestureDetector(
|
|
onTap: () =>
|
|
Get.to(() => const ForgetPasswordScreen()),
|
|
child: Text(
|
|
'Forgot password?',
|
|
style: GoogleFonts.getFont(
|
|
'Roboto',
|
|
fontWeight: FontWeight.w400,
|
|
fontSize: 20,
|
|
height: 1,
|
|
letterSpacing: -0.2,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 30),
|
|
Obx(
|
|
() => CustomButton(
|
|
text: "Login",
|
|
onPressed: () {
|
|
if (formKey.currentState!.validate()) {
|
|
// Perform login action
|
|
authController.login();
|
|
}
|
|
},
|
|
isLoading: authController.isLoading.value,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|