132 lines
4.5 KiB
Dart
132 lines
4.5 KiB
Dart
|
|
import 'package:adaptix/adaptix.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
import 'package:sapaly_shop/components/custom_button.dart';
|
||
|
|
import 'package:sapaly_shop/components/snack_message.dart';
|
||
|
|
import 'package:sapaly_shop/components/text_field.dart';
|
||
|
|
import 'package:sapaly_shop/providers/auth_provider/auth_provider.dart';
|
||
|
|
import 'package:sapaly_shop/screens/auth/register.dart';
|
||
|
|
import 'package:sapaly_shop/services/app_constants.dart';
|
||
|
|
import 'package:sapaly_shop/themes/app_theme.dart';
|
||
|
|
|
||
|
|
import '../../services/page_navigator.dart';
|
||
|
|
|
||
|
|
class LoginScreen extends StatefulWidget {
|
||
|
|
const LoginScreen({super.key});
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _LoginScreenState extends State<LoginScreen> {
|
||
|
|
final TextEditingController _email = TextEditingController();
|
||
|
|
final TextEditingController _password = TextEditingController();
|
||
|
|
|
||
|
|
@override
|
||
|
|
void dispose() {
|
||
|
|
_email.clear();
|
||
|
|
_password.clear();
|
||
|
|
super.dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return Scaffold(
|
||
|
|
body: Center(
|
||
|
|
child: Container(
|
||
|
|
margin: EdgeInsets.symmetric(
|
||
|
|
horizontal: AppConstants.horizontalPadding(context),
|
||
|
|
),
|
||
|
|
padding: EdgeInsets.symmetric(
|
||
|
|
horizontal: AppConstants.horizontalPadding(context),
|
||
|
|
),
|
||
|
|
height: AppConstants.deviceHeight(context) / (1.4),
|
||
|
|
width: double.infinity,
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
border: Border.all(
|
||
|
|
width: 2.adaptedPx(),
|
||
|
|
color: AppTheme.blackColor.withOpacity(0.1),
|
||
|
|
),
|
||
|
|
borderRadius: BorderRadius.circular(15.adaptedPx()),
|
||
|
|
),
|
||
|
|
child: Column(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
|
children: [
|
||
|
|
Row(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
|
children: [
|
||
|
|
Image.asset('assets/images/sapalyLogo.png'),
|
||
|
|
SizedBox(width: 20.adaptedPx()),
|
||
|
|
Text(
|
||
|
|
AppConstants.kAppName,
|
||
|
|
style:
|
||
|
|
Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
|
||
|
|
color: AppTheme.blackColor,
|
||
|
|
fontWeight: FontWeight.w600,
|
||
|
|
fontSize: 20.adaptedPx(),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
SizedBox(height: 20.adaptedPx()),
|
||
|
|
customTextField(
|
||
|
|
title: 'Email',
|
||
|
|
context: context,
|
||
|
|
hint: 'Enter your valid email address',
|
||
|
|
controller: _email,
|
||
|
|
),
|
||
|
|
SizedBox(height: 20.adaptedPx()),
|
||
|
|
customTextField(
|
||
|
|
title: 'Password',
|
||
|
|
context: context,
|
||
|
|
hint: 'Enter your secured password',
|
||
|
|
controller: _password,
|
||
|
|
),
|
||
|
|
SizedBox(height: 45.adaptedPx()),
|
||
|
|
Consumer<AuthenticatonProvider>(builder: (context, auth, child) {
|
||
|
|
return customButton(
|
||
|
|
text: 'Login',
|
||
|
|
tap: () {
|
||
|
|
if (_email.text.isEmpty || _password.text.isEmpty) {
|
||
|
|
showMessage(
|
||
|
|
context: context,
|
||
|
|
message: 'All fields are required',
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
auth.login(
|
||
|
|
email: _email.text.trim(),
|
||
|
|
password: _password.text.trim());
|
||
|
|
}
|
||
|
|
},
|
||
|
|
context: context,
|
||
|
|
statusText: 'Loggin in...',
|
||
|
|
status: auth.isLoading,
|
||
|
|
);
|
||
|
|
}),
|
||
|
|
Text(
|
||
|
|
'Or',
|
||
|
|
textAlign: TextAlign.center,
|
||
|
|
style: Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
|
||
|
|
color: AppTheme.blackColor,
|
||
|
|
fontSize: 18.adaptedPx(),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
customButton(
|
||
|
|
text: 'Register',
|
||
|
|
tap: () {
|
||
|
|
PageNavigator(ctx: context).nextPage(
|
||
|
|
page: const RegisterScreen(),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
context: context,
|
||
|
|
isValid: false,
|
||
|
|
status: false,
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|