11import 'package:flutter/material.dart' ;
22import 'package:fluttertoast/fluttertoast.dart' ;
3+ import 'package:givison/auth.services.dart' ;
34import 'package:givison/common/size.dart' ;
45import 'package:givison/common/text_strings.dart' ;
56import 'package:firebase_auth/firebase_auth.dart' ;
@@ -23,9 +24,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
2324 final passwordController = TextEditingController ();
2425 final phController = TextEditingController ();
2526 final nameController = TextEditingController ();
26-
27- final FirebaseAuth _auth = FirebaseAuth .instance;
28- final fireStore = FirebaseFirestore .instance.collection ("users" );
27+ final AuthService _authService = AuthService (); // Initialize AuthService
2928
3029 @override
3130 void dispose () {
@@ -34,28 +33,20 @@ class _SignUpScreenState extends State<SignUpScreen> {
3433 passwordController.dispose ();
3534 }
3635
37- void loginn () {
36+ void signup () async {
3837 setState (() {
3938 loading = true ;
4039 });
41- _auth
42- .createUserWithEmailAndPassword (
43- email: emailController.text.toString (),
44- password: passwordController.text.toString ())
45- .then ((value) {
46- Navigator .push (
47- context, MaterialPageRoute (builder: (context) => const Verify ()));
48- }).onError ((error, stackTrace) {
49- Utils ().toastMessage (error.toString ());
50- });
51- }
52-
53- void uploadingData () async {
54- await FirebaseFirestore .instance.collection ("Users" ).add ({
55- 'Name' : nameController.text.toString (),
56- 'E-mail' : emailController.text.toString (),
57- 'Phone Number' : phController.text.toString (),
58- 'Pw' : passwordController.text.toString (),
40+ await _authService.signup (
41+ context,
42+ emailController.text,
43+ passwordController.text,
44+ nameController.text,
45+ phController.text,
46+ ).whenComplete (() {
47+ setState (() {
48+ loading = false ;
49+ });
5950 });
6051 }
6152
@@ -87,12 +78,12 @@ class _SignUpScreenState extends State<SignUpScreen> {
8778 const SizedBox (height: 40 ),
8879 const Text (
8980 tSignupTitle,
90- style: TextStyles .blackTitle
81+ style: TextStyles .blackTitle,
9182 ),
9283 const SizedBox (height: 8 ),
9384 const Text (
9485 tSignupSubTitle,
95- style: TextStyles .blackSubTitle
86+ style: TextStyles .blackSubTitle,
9687 ),
9788 const SizedBox (height: 40 ),
9889 Form (
@@ -199,22 +190,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
199190 if (_formKey.currentState! .validate ()) {
200191 String email = emailController.text;
201192 if (email.contains ('@iiitm.ac.in' )) {
202- loginn ();
203- String name = nameController.text;
204- String ph = phController.text;
205- String pw = passwordController.text;
206- fireStore
207- .doc (email)
208- .set ({
209- 'Name' : name,
210- 'Email' : email,
211- 'Phone' : ph,
212- 'Password' : pw
213- })
214- .then ((value) {})
215- .onError ((error, stackStrace) {
216- Utils ().toastMessage (error.toString ());
217- });
193+ signup ();
218194 } else {
219195 Fluttertoast .showToast (
220196 msg: "Not the Organization Mail" );
@@ -231,7 +207,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
231207 ),
232208 child: const Text (
233209 tSignupButton,
234- style: TextStyles .loginButton
210+ style: TextStyles .loginButton,
235211 ),
236212 ),
237213 ),
0 commit comments