autentificacion por celular
This commit is contained in:
@@ -1,20 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
import 'package:prosappco/src/provider/google_sign.dart';
|
|
||||||
import 'package:prosappco/src/screens/login.dart';
|
import 'package:prosappco/src/screens/login.dart';
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
|
||||||
import 'firebase_options.dart';
|
import 'firebase_options.dart';
|
||||||
import 'package:prosappco/src/provider/google_sign.dart';
|
|
||||||
import 'package:prosappco/src/screens/login.dart';
|
|
||||||
import 'package:prosappco/src/screens/welcome.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
|
||||||
import 'package:prosappco/src/screens/register.dart';
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -24,22 +13,6 @@ void main() async {
|
|||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
final FirebaseAuth _auth = FirebaseAuth.instance;
|
|
||||||
final GoogleSignIn googleSignIn = GoogleSignIn();
|
|
||||||
|
|
||||||
Future<UserCredential> signInWithGoogle() async {
|
|
||||||
final GoogleSignInAccount? googleSignInAccount = await googleSignIn.signIn();
|
|
||||||
final GoogleSignInAuthentication googleSignInAuthentication =
|
|
||||||
await googleSignInAccount!.authentication;
|
|
||||||
|
|
||||||
final AuthCredential credential = GoogleAuthProvider.credential(
|
|
||||||
accessToken: googleSignInAuthentication.accessToken,
|
|
||||||
idToken: googleSignInAuthentication.idToken,
|
|
||||||
);
|
|
||||||
|
|
||||||
return await _auth.signInWithCredential(credential);
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:ffi';
|
|
||||||
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
import 'package:google_sign_in/google_sign_in.dart';
|
||||||
@@ -14,10 +12,11 @@ class AuthenticationRepository extends GetxController {
|
|||||||
final _auth = FirebaseAuth.instance;
|
final _auth = FirebaseAuth.instance;
|
||||||
late final Rx<User?> firebaseUser;
|
late final Rx<User?> firebaseUser;
|
||||||
final GoogleSignIn googleSignIn = GoogleSignIn();
|
final GoogleSignIn googleSignIn = GoogleSignIn();
|
||||||
|
var verificationId = ''.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
Future.delayed(const Duration(seconds: 6));
|
// Future.delayed(const Duration(seconds: 6));
|
||||||
firebaseUser = Rx<User?>(_auth.currentUser);
|
firebaseUser = Rx<User?>(_auth.currentUser);
|
||||||
firebaseUser.bindStream(_auth.userChanges());
|
firebaseUser.bindStream(_auth.userChanges());
|
||||||
ever(firebaseUser, _setInitialScreen);
|
ever(firebaseUser, _setInitialScreen);
|
||||||
@@ -29,6 +28,35 @@ class AuthenticationRepository extends GetxController {
|
|||||||
: Get.offAll(() => const WelcomeScreen());
|
: Get.offAll(() => const WelcomeScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> phoneAuthentication(String phoneNo) async {
|
||||||
|
await _auth.verifyPhoneNumber(
|
||||||
|
phoneNumber: phoneNo,
|
||||||
|
verificationCompleted: (credential) async {
|
||||||
|
await _auth.signInWithCredential(credential);
|
||||||
|
},
|
||||||
|
codeSent: (verificationId, resendToken) {
|
||||||
|
this.verificationId.value = verificationId;
|
||||||
|
},
|
||||||
|
codeAutoRetrievalTimeout: (verificationId) {
|
||||||
|
this.verificationId.value = verificationId;
|
||||||
|
},
|
||||||
|
verificationFailed: (e) {
|
||||||
|
if (e.code == 'invalid-phone-number') {
|
||||||
|
Get.snackbar('Error', 'El numero no es valido.');
|
||||||
|
} else {
|
||||||
|
Get.snackbar('Error', 'Algo ha ido mal. Inténtalo de nuevo. $e');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> verifyOTP(String otp) async {
|
||||||
|
var credentials = await _auth.signInWithCredential(
|
||||||
|
PhoneAuthProvider.credential(
|
||||||
|
verificationId: verificationId.value, smsCode: otp));
|
||||||
|
return credentials.user != null ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> createUserWithEmailAndPassword(
|
Future<void> createUserWithEmailAndPassword(
|
||||||
String email, String password) async {
|
String email, String password) async {
|
||||||
try {
|
try {
|
||||||
@@ -54,17 +82,20 @@ class AuthenticationRepository extends GetxController {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<UserCredential> signInWithGoogle() async {
|
Future<void> signInWithGoogle() async {
|
||||||
final GoogleSignInAccount? googleSignInAccount =
|
try {
|
||||||
await googleSignIn.signIn();
|
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
|
||||||
final GoogleSignInAuthentication googleSignInAuthentication =
|
final GoogleSignInAuthentication googleAuth =
|
||||||
await googleSignInAccount!.authentication;
|
await googleUser!.authentication;
|
||||||
|
final credential = GoogleAuthProvider.credential(
|
||||||
final AuthCredential credential = GoogleAuthProvider.credential(
|
accessToken: googleAuth.accessToken,
|
||||||
accessToken: googleSignInAuthentication.accessToken,
|
idToken: googleAuth.idToken,
|
||||||
idToken: googleSignInAuthentication.idToken,
|
);
|
||||||
);
|
await FirebaseAuth.instance.signInWithCredential(credential);
|
||||||
|
} catch (e) {
|
||||||
return await _auth.signInWithCredential(credential);
|
print('Error - ${e}');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> logout() async => _auth.signOut();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
|
import 'package:prosappco/src/screens/welcome.dart';
|
||||||
|
|
||||||
|
class OTPController extends GetxController {
|
||||||
|
static OTPController get instance => Get.find();
|
||||||
|
|
||||||
|
Future<void> verifyOTP(String otp) async {
|
||||||
|
var isVerified = AuthenticationRepository.instance.verifyOTP(otp);
|
||||||
|
await isVerified ? Get.offAll(const WelcomeScreen()) : Get.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
|
|
||||||
|
class PhoneAuthController extends GetxController {
|
||||||
|
static PhoneAuthController get instance => Get.find();
|
||||||
|
|
||||||
|
final phoneNo = TextEditingController();
|
||||||
|
|
||||||
|
void phoneAuthentication(String phoneNo) {
|
||||||
|
AuthenticationRepository.instance.phoneAuthentication(phoneNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
|
|||||||
class RegisterController extends GetxController {
|
class RegisterController extends GetxController {
|
||||||
static RegisterController get instance => Get.find();
|
static RegisterController get instance => Get.find();
|
||||||
|
|
||||||
// textField controllers to get data from textfields
|
|
||||||
final name = TextEditingController();
|
final name = TextEditingController();
|
||||||
final email = TextEditingController();
|
final email = TextEditingController();
|
||||||
final password = TextEditingController();
|
final password = TextEditingController();
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
|
||||||
|
|
||||||
class GoogleSignProvider extends ChangeNotifier {
|
|
||||||
final googleSign = GoogleSignIn();
|
|
||||||
|
|
||||||
GoogleSignInAccount? _user;
|
|
||||||
|
|
||||||
GoogleSignInAccount get user => _user!;
|
|
||||||
|
|
||||||
Future googleLogin() async {
|
|
||||||
final googleUser = await googleSign.signIn();
|
|
||||||
if (googleUser == null) return;
|
|
||||||
_user = googleUser;
|
|
||||||
|
|
||||||
final googleAuth = await googleUser.authentication;
|
|
||||||
|
|
||||||
final credential = GoogleAuthProvider.credential(
|
|
||||||
accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
|
|
||||||
|
|
||||||
await FirebaseAuth.instance.signInWithCredential(credential);
|
|
||||||
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_otp_text_field/flutter_otp_text_field.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:prosappco/src/controllers/otp_controller.dart';
|
||||||
|
|
||||||
class CodeValidationScreen extends StatefulWidget {
|
class CodeValidationScreen extends StatefulWidget {
|
||||||
const CodeValidationScreen({super.key});
|
const CodeValidationScreen({super.key});
|
||||||
@@ -8,8 +11,11 @@ class CodeValidationScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CodeValidationScreenState extends State<CodeValidationScreen> {
|
class _CodeValidationScreenState extends State<CodeValidationScreen> {
|
||||||
|
final controller = Get.put(OTPController());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var otp;
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
@@ -76,7 +82,7 @@ class _CodeValidationScreenState extends State<CodeValidationScreen> {
|
|||||||
child: TextField(
|
child: TextField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
hintText: '3102589636',
|
hintText: '+57',
|
||||||
suffixIcon: Icon(Icons.edit),
|
suffixIcon: Icon(Icons.edit),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -102,37 +108,50 @@ class _CodeValidationScreenState extends State<CodeValidationScreen> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(bottom: 20),
|
padding: EdgeInsets.only(bottom: 20),
|
||||||
child: TextField(
|
child: OtpTextField(
|
||||||
maxLength: 4,
|
numberOfFields: 6,
|
||||||
|
fillColor: Colors.black.withOpacity(0.1),
|
||||||
|
filled: true,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
onSubmit: (code) {
|
||||||
enabledBorder: OutlineInputBorder(
|
otp = code;
|
||||||
borderSide: BorderSide(color: Color(0xFFECECEC)),
|
OTPController.instance.verifyOTP(otp);
|
||||||
borderRadius: BorderRadius.all(
|
},
|
||||||
Radius.circular(50),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Color(0xFFECECEC)),
|
|
||||||
borderRadius: BorderRadius.all(
|
|
||||||
Radius.circular(50),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
hintText: '_ _ _ _',
|
|
||||||
fillColor: Color.fromARGB(255, 239, 239, 239),
|
|
||||||
filled: true,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
letterSpacing: 12.0,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
// child: TextField(
|
||||||
|
// onSubmitted:
|
||||||
|
// maxLength: 6,
|
||||||
|
// keyboardType: TextInputType.number,
|
||||||
|
// decoration: InputDecoration(
|
||||||
|
// enabledBorder: OutlineInputBorder(
|
||||||
|
// borderSide: BorderSide(color: Color(0xFFECECEC)),
|
||||||
|
// borderRadius: BorderRadius.all(
|
||||||
|
// Radius.circular(50),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// focusedBorder: OutlineInputBorder(
|
||||||
|
// borderSide: BorderSide(color: Color(0xFFECECEC)),
|
||||||
|
// borderRadius: BorderRadius.all(
|
||||||
|
// Radius.circular(50),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// hintText: '_ _ _ _ _ _',
|
||||||
|
// fillColor: Color.fromARGB(255, 239, 239, 239),
|
||||||
|
// filled: true,
|
||||||
|
// ),
|
||||||
|
// textAlign: TextAlign.center,
|
||||||
|
// style: TextStyle(
|
||||||
|
// letterSpacing: 10.0,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(bottom: 40),
|
padding: EdgeInsets.only(bottom: 40),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
OTPController.instance.verifyOTP(otp);
|
||||||
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Validar código',
|
'Validar código',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
|||||||
+34
-28
@@ -1,12 +1,10 @@
|
|||||||
import 'package:flutter/gestures.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:prosappco/src/provider/google_sign.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
|
import 'package:prosappco/src/controllers/phone_auth_controller.dart';
|
||||||
import 'package:prosappco/src/screens/code_validation.dart';
|
import 'package:prosappco/src/screens/code_validation.dart';
|
||||||
import 'package:prosappco/src/screens/login_email.dart';
|
import 'package:prosappco/src/screens/login_email.dart';
|
||||||
import 'package:prosappco/src/screens/register.dart';
|
import 'package:prosappco/src/screens/register.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:flutter/gestures.dart';
|
|
||||||
|
|
||||||
class LoginScreen extends StatefulWidget {
|
class LoginScreen extends StatefulWidget {
|
||||||
const LoginScreen({super.key});
|
const LoginScreen({super.key});
|
||||||
@@ -16,6 +14,9 @@ class LoginScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LoginScreenState extends State<LoginScreen> {
|
class _LoginScreenState extends State<LoginScreen> {
|
||||||
|
final controller = Get.put(PhoneAuthController());
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
@@ -67,24 +68,28 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18.0, color: Color(0xFF65676B))),
|
fontSize: 18.0, color: Color(0xFF65676B))),
|
||||||
)),
|
)),
|
||||||
const Padding(
|
Form(
|
||||||
padding: EdgeInsets.only(bottom: 10),
|
key: _formKey,
|
||||||
child: TextField(
|
child: Padding(
|
||||||
decoration: InputDecoration(
|
padding: EdgeInsets.only(bottom: 10),
|
||||||
enabledBorder: OutlineInputBorder(
|
child: TextFormField(
|
||||||
borderSide: BorderSide(color: Color(0xFFECECEC)),
|
controller: controller.phoneNo,
|
||||||
borderRadius: BorderRadius.all(
|
decoration: InputDecoration(
|
||||||
Radius.circular(50),
|
enabledBorder: OutlineInputBorder(
|
||||||
)),
|
borderSide: BorderSide(color: Color(0xFFECECEC)),
|
||||||
focusedBorder: OutlineInputBorder(
|
borderRadius: BorderRadius.all(
|
||||||
borderSide: BorderSide(color: Color(0xFFECECEC)),
|
Radius.circular(50),
|
||||||
borderRadius: BorderRadius.all(
|
)),
|
||||||
Radius.circular(50),
|
focusedBorder: OutlineInputBorder(
|
||||||
)),
|
borderSide: BorderSide(color: Color(0xFFECECEC)),
|
||||||
hintText: '3163225944',
|
borderRadius: BorderRadius.all(
|
||||||
fillColor: Color.fromARGB(255, 239, 239, 239),
|
Radius.circular(50),
|
||||||
filled: true,
|
)),
|
||||||
prefixIcon: Icon(Icons.phone_android_outlined)),
|
hintText: '+57',
|
||||||
|
fillColor: Color.fromARGB(255, 239, 239, 239),
|
||||||
|
filled: true,
|
||||||
|
prefixIcon: Icon(Icons.phone_android_outlined)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Padding(
|
const Padding(
|
||||||
@@ -98,11 +103,12 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
child: Center(
|
child: Center(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
if (_formKey.currentState!.validate()) {
|
||||||
context,
|
PhoneAuthController.instance.phoneAuthentication(
|
||||||
MaterialPageRoute(
|
controller.phoneNo.text.trim(),
|
||||||
builder: (context) => CodeValidationScreen()),
|
);
|
||||||
);
|
Get.to(() => const CodeValidationScreen());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Enviar código',
|
'Enviar código',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:prosappco/main.dart';
|
import 'package:prosappco/main.dart';
|
||||||
import 'package:prosappco/src/provider/google_sign.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
import 'package:prosappco/src/screens/login.dart';
|
import 'package:prosappco/src/screens/login.dart';
|
||||||
import 'package:prosappco/src/screens/welcome.dart';
|
import 'package:prosappco/src/screens/welcome.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -83,22 +83,8 @@ class _LoginEmailScreenState extends State<LoginEmailScreen> {
|
|||||||
padding: EdgeInsets.only(bottom: 20),
|
padding: EdgeInsets.only(bottom: 20),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
try {
|
await AuthenticationRepository.instance
|
||||||
final UserCredential userCredential =
|
.signInWithGoogle();
|
||||||
await signInWithGoogle();
|
|
||||||
// Si la autenticación es exitosa, realiza una acción
|
|
||||||
// Por ejemplo, navegar a otra pantalla:
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => WelcomeScreen()));
|
|
||||||
} catch (e) {
|
|
||||||
// Si ocurre un error durante la autenticación, muestra un mensaje al usuario
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
||||||
content: Text(
|
|
||||||
'Error al iniciar sesion intentalo de nuevo'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
primary: Color(0xFF2BA4EC),
|
primary: Color(0xFF2BA4EC),
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:prosappco/main.dart';
|
import 'package:prosappco/main.dart';
|
||||||
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
import 'package:prosappco/src/controllers/register_controller.dart';
|
import 'package:prosappco/src/controllers/register_controller.dart';
|
||||||
import 'package:prosappco/src/provider/google_sign.dart';
|
|
||||||
import 'package:prosappco/src/screens/login.dart';
|
import 'package:prosappco/src/screens/login.dart';
|
||||||
import 'package:prosappco/src/screens/welcome.dart';
|
import 'package:prosappco/src/screens/welcome.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -84,22 +84,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
padding: EdgeInsets.only(bottom: 20),
|
padding: EdgeInsets.only(bottom: 20),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
try {
|
await AuthenticationRepository.instance
|
||||||
final UserCredential userCredential =
|
.signInWithGoogle();
|
||||||
await signInWithGoogle();
|
|
||||||
// Si la autenticación es exitosa, realiza una acción
|
|
||||||
// Por ejemplo, navegar a otra pantalla:
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => WelcomeScreen()));
|
|
||||||
} catch (e) {
|
|
||||||
// Si ocurre un error durante la autenticación, muestra un mensaje al usuario
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
||||||
content: Text(
|
|
||||||
'Error al iniciar sesion intentalo de nuevo'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
primary: Color(0xFF2BA4EC),
|
primary: Color(0xFF2BA4EC),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
|
|
||||||
class WelcomeScreen extends StatefulWidget {
|
class WelcomeScreen extends StatefulWidget {
|
||||||
const WelcomeScreen({super.key});
|
const WelcomeScreen({super.key});
|
||||||
@@ -34,6 +35,34 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
|||||||
height: 100,
|
height: 100,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Container(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.topRight,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
AuthenticationRepository.instance.logout();
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Cerrar Sesión',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
primary: Color(0xFF2BA4EC),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
),
|
||||||
|
elevation: 0,
|
||||||
|
minimumSize: Size(150, 40),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 20),
|
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 20),
|
||||||
margin: const EdgeInsets.only(top: 170),
|
margin: const EdgeInsets.only(top: 170),
|
||||||
|
|||||||
@@ -126,6 +126,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.0.1"
|
||||||
|
flutter_otp_text_field:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_otp_text_field
|
||||||
|
sha256: c9164ba391071fb9783698256ddbb9efc960cfed056d843db164711c65b1b114
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.1"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ dependencies:
|
|||||||
provider: ^6.0.5
|
provider: ^6.0.5
|
||||||
get: ^4.6.5
|
get: ^4.6.5
|
||||||
font_awesome_flutter: ^10.4.0
|
font_awesome_flutter: ^10.4.0
|
||||||
|
flutter_otp_text_field: ^1.1.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user