178 lines
6.6 KiB
Dart
178 lines
6.6 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/Components/wrapper.dart';
|
|
import 'package:securify/Screen/login.dart';
|
|
import 'package:firebase_database/firebase_database.dart';
|
|
|
|
class Signup extends StatefulWidget {
|
|
const Signup({super.key});
|
|
|
|
@override
|
|
State<Signup> createState() => _SignupState();
|
|
}
|
|
|
|
class _SignupState extends State<Signup> {
|
|
TextEditingController username = TextEditingController();
|
|
TextEditingController email = TextEditingController();
|
|
TextEditingController phone = TextEditingController();
|
|
TextEditingController coderegistration = TextEditingController();
|
|
TextEditingController password = TextEditingController();
|
|
|
|
Future<void> signup() async {
|
|
try {
|
|
UserCredential userCredential = await FirebaseAuth.instance
|
|
.createUserWithEmailAndPassword(
|
|
email: email.text, password: password.text);
|
|
|
|
String uid = userCredential.user!.uid;
|
|
|
|
DatabaseReference userRef =
|
|
FirebaseDatabase.instance.ref().child('Users').child(uid);
|
|
|
|
await userRef.set({
|
|
'username': username.text,
|
|
'email': email.text,
|
|
'phone': phone.text,
|
|
'coderegistration': coderegistration.text,
|
|
'created_at': ServerValue.timestamp,
|
|
});
|
|
|
|
Get.offAll(const Wrapper());
|
|
} on FirebaseAuthException catch (e) {
|
|
Get.snackbar('Error', e.message ?? 'Registration Failed');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return 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: 40),
|
|
child: const Text(
|
|
"REGISTER",
|
|
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: username,
|
|
decoration: const InputDecoration(labelText: "Username"),
|
|
),
|
|
),
|
|
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: phone,
|
|
decoration: const InputDecoration(labelText: "Phone"),
|
|
),
|
|
),
|
|
SizedBox(height: size.height * 0.03),
|
|
Container(
|
|
alignment: Alignment.center,
|
|
margin: const EdgeInsets.symmetric(horizontal: 40),
|
|
child: TextField(
|
|
controller: coderegistration,
|
|
decoration:
|
|
const InputDecoration(labelText: "Code Registration"),
|
|
),
|
|
),
|
|
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,
|
|
),
|
|
),
|
|
SizedBox(height: size.height * 0.05),
|
|
Container(
|
|
alignment: Alignment.centerRight,
|
|
margin:
|
|
const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
|
|
child: ElevatedButton(
|
|
onPressed: (() => signup()),
|
|
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 UP",
|
|
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 Login()))
|
|
},
|
|
child: const Text(
|
|
"Already Have an Account? Sign in",
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF2661FA)),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|