|
|
|
@ -1,10 +1,13 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
|
|
|
import 'package:tangheem/api/authentication_api_client.dart';
|
|
|
|
import 'package:tangheem/classes/colors.dart';
|
|
|
|
import 'package:tangheem/classes/colors.dart';
|
|
|
|
import 'package:tangheem/classes/utils.dart';
|
|
|
|
import 'package:tangheem/classes/utils.dart';
|
|
|
|
|
|
|
|
import 'package:tangheem/models/authentication_user_model.dart';
|
|
|
|
import 'package:tangheem/ui/screens/forgot_password_screen.dart';
|
|
|
|
import 'package:tangheem/ui/screens/forgot_password_screen.dart';
|
|
|
|
import 'package:tangheem/ui/screens/registration_screen.dart';
|
|
|
|
import 'package:tangheem/ui/screens/registration_screen.dart';
|
|
|
|
import 'package:tangheem/widgets/common_textfield_widget.dart';
|
|
|
|
import 'package:tangheem/widgets/common_textfield_widget.dart';
|
|
|
|
|
|
|
|
import 'package:tangheem/extensions/email_validator.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
|
|
static const String routeName = "/login";
|
|
|
|
static const String routeName = "/login";
|
|
|
|
@ -18,10 +21,12 @@ class LoginScreen extends StatefulWidget {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
TextEditingController _usernameController = TextEditingController();
|
|
|
|
TextEditingController _emailController = TextEditingController();
|
|
|
|
TextEditingController _passwordController = TextEditingController();
|
|
|
|
TextEditingController _passwordController = TextEditingController();
|
|
|
|
bool _isRemember = true;
|
|
|
|
bool _isRemember = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AuthenticationUserModel _authenticationUser;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
@ -32,6 +37,18 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
super.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void performLogin(String email, String password) async {
|
|
|
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
_authenticationUser = await AuthenticationApiClient().authenticateUser(email, password);
|
|
|
|
|
|
|
|
Utils.showToast("Login successfully");
|
|
|
|
|
|
|
|
} catch (ex, tr) {
|
|
|
|
|
|
|
|
Utils.handleException(ex, null);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
@ -65,7 +82,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
CommonTextFieldWidget(hint: "اسم المستخدم", controller: _usernameController, prefixIcon: "assets/icons/user.svg"),
|
|
|
|
// todo @discuss wiht haroon to change hint to email, because auth depends on email
|
|
|
|
|
|
|
|
CommonTextFieldWidget(hint: "اسم المستخدم", controller: _emailController, prefixIcon: "assets/icons/user.svg"),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
CommonTextFieldWidget(hint: "كلمة المرور", controller: _passwordController, isPassword: true, prefixIcon: "assets/icons/password.svg"),
|
|
|
|
CommonTextFieldWidget(hint: "كلمة المرور", controller: _passwordController, isPassword: true, prefixIcon: "assets/icons/password.svg"),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
@ -74,15 +92,18 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
height: 50,
|
|
|
|
height: 50,
|
|
|
|
child: TextButton(
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
onPressed: () {
|
|
|
|
if (_usernameController.text.length < 1) {
|
|
|
|
if (_emailController.text.length < 1) {
|
|
|
|
Utils.showToast("Username is empty.");
|
|
|
|
Utils.showToast("Email is empty.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (!_emailController.text.isValidEmail()) {
|
|
|
|
|
|
|
|
Utils.showToast("Invalid email.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_passwordController.text.length < 1) {
|
|
|
|
if (_passwordController.text.length < 1) {
|
|
|
|
Utils.showToast("Password is empty.");
|
|
|
|
Utils.showToast("Password is empty.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Utils.showToast("Login successfully");
|
|
|
|
performLogin(_emailController.text, _passwordController.text);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
primary: Colors.white,
|
|
|
|
primary: Colors.white,
|
|
|
|
|