164 lines
6.4 KiB
Dart
164 lines
6.4 KiB
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:securify/Components/background.dart';
|
|
import 'package:securify/Screen/forgot_password.dart';
|
|
import 'package:securify/Screen/register.dart';
|
|
|
|
class Login extends StatefulWidget {
|
|
const Login({super.key});
|
|
|
|
@override
|
|
State<Login> createState() => _LoginState();
|
|
}
|
|
|
|
class _LoginState extends State<Login> {
|
|
TextEditingController email = TextEditingController();
|
|
TextEditingController password = TextEditingController();
|
|
|
|
bool isloading = false;
|
|
|
|
signIn() async {
|
|
setState(() {
|
|
isloading = true;
|
|
});
|
|
try {
|
|
await FirebaseAuth.instance.signInWithEmailAndPassword(
|
|
email: email.text, password: password.text);
|
|
} on FirebaseAuthException catch (e) {
|
|
Get.snackbar("Error Msg", e.code);
|
|
} catch (e) {
|
|
Get.snackbar("Error Msg", e.toString());
|
|
}
|
|
setState(() {
|
|
isloading = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return isloading
|
|
? const Center(
|
|
child: CircularProgressIndicator(),
|
|
)
|
|
: Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
body: Background(
|
|
child: SafeArea(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Container(
|
|
alignment: Alignment.centerLeft,
|
|
padding: const EdgeInsets.symmetric(horizontal: 37),
|
|
child: const Text(
|
|
"LOGIN",
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF2661FA),
|
|
fontSize: 36),
|
|
textAlign: TextAlign.left,
|
|
),
|
|
),
|
|
SizedBox(height: size.height * 0.03),
|
|
Container(
|
|
alignment: Alignment.center,
|
|
margin: const EdgeInsets.symmetric(horizontal: 40),
|
|
child: TextField(
|
|
controller: email,
|
|
decoration: const InputDecoration(labelText: "Email"),
|
|
),
|
|
),
|
|
SizedBox(height: size.height * 0.03),
|
|
Container(
|
|
alignment: Alignment.center,
|
|
margin: const EdgeInsets.symmetric(horizontal: 40),
|
|
child: TextField(
|
|
controller: password,
|
|
decoration:
|
|
const InputDecoration(labelText: "Password"),
|
|
obscureText: true,
|
|
),
|
|
),
|
|
Container(
|
|
alignment: Alignment.centerRight,
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: 40, vertical: 10),
|
|
child: GestureDetector(
|
|
onTap: () => {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const ForgotPassword()))
|
|
},
|
|
child: const Text(
|
|
"Forgot your password?",
|
|
style: TextStyle(
|
|
fontSize: 12, color: Color(0xFF2661FA)),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: size.height * 0.05),
|
|
Container(
|
|
alignment: Alignment.centerRight,
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: 40, vertical: 10),
|
|
child: ElevatedButton(
|
|
onPressed: (() => signIn()),
|
|
style: ElevatedButton.styleFrom(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(80.0)),
|
|
padding: const EdgeInsets.all(0),
|
|
),
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
height: 50.0,
|
|
width: size.width * 0.5,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(80.0),
|
|
gradient: const LinearGradient(colors: [
|
|
Color.fromARGB(255, 255, 136, 34),
|
|
Color.fromARGB(255, 255, 177, 41)
|
|
])),
|
|
padding: const EdgeInsets.all(0),
|
|
child: const Text(
|
|
"SIGN IN",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
alignment: Alignment.centerRight,
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: 40, vertical: 10),
|
|
child: GestureDetector(
|
|
onTap: () => {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const Signup()))
|
|
},
|
|
child: const Text(
|
|
"Don't Have an Account? Sign up",
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF2661FA)),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|