From 1884b82d83a7dba2e7974d6297a624d5fa67f481 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Tue, 28 Mar 2023 17:35:52 -0500 Subject: [PATCH] Register con gmail y screen welcome --- android/app/google-services.json | 11 +++- ios/Runner/GoogleService-Info.plist | 36 ++++++++++++ ios/firebase_app_id_file.json | 7 +++ lib/firebase_options.dart | 84 +++++++++++++++++++++++++++ lib/main.dart | 5 ++ lib/src/screens/login_email.dart | 40 +++++++++++-- lib/src/screens/welcome.dart | 84 +++++++++++++++++++++++++++ macos/Runner/GoogleService-Info.plist | 36 ++++++++++++ macos/firebase_app_id_file.json | 7 +++ 9 files changed, 304 insertions(+), 6 deletions(-) create mode 100644 ios/Runner/GoogleService-Info.plist create mode 100644 ios/firebase_app_id_file.json create mode 100644 lib/firebase_options.dart create mode 100644 macos/Runner/GoogleService-Info.plist create mode 100644 macos/firebase_app_id_file.json diff --git a/android/app/google-services.json b/android/app/google-services.json index 7295933..87544c7 100644 --- a/android/app/google-services.json +++ b/android/app/google-services.json @@ -22,7 +22,7 @@ } }, { - "client_id": "245204384533-51jep2regc9t57m0dlhcskvh6u3o99hb.apps.googleusercontent.com", + "client_id": "245204384533-4lo58sle0aclpq7jp4drepabs7v1tqe2.apps.googleusercontent.com", "client_type": 3 } ], @@ -35,8 +35,15 @@ "appinvite_service": { "other_platform_oauth_client": [ { - "client_id": "245204384533-51jep2regc9t57m0dlhcskvh6u3o99hb.apps.googleusercontent.com", + "client_id": "245204384533-4lo58sle0aclpq7jp4drepabs7v1tqe2.apps.googleusercontent.com", "client_type": 3 + }, + { + "client_id": "245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn.apps.googleusercontent.com", + "client_type": 2, + "ios_info": { + "bundle_id": "com.example.prosappco" + } } ] } diff --git a/ios/Runner/GoogleService-Info.plist b/ios/Runner/GoogleService-Info.plist new file mode 100644 index 0000000..3b62a42 --- /dev/null +++ b/ios/Runner/GoogleService-Info.plist @@ -0,0 +1,36 @@ + + + + + CLIENT_ID + 245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn + ANDROID_CLIENT_ID + 245204384533-7p2j0go97da4gp062s7enop0ab8q7a7p.apps.googleusercontent.com + API_KEY + AIzaSyDUhnkNkeEPkqcwVo5EWr63q3oEX6bDGic + GCM_SENDER_ID + 245204384533 + PLIST_VERSION + 1 + BUNDLE_ID + com.example.prosappco + PROJECT_ID + prosapp-5747a + STORAGE_BUCKET + prosapp-5747a.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:245204384533:ios:aeb233e55c5ddf7a9f871c + + \ No newline at end of file diff --git a/ios/firebase_app_id_file.json b/ios/firebase_app_id_file.json new file mode 100644 index 0000000..a4bc04d --- /dev/null +++ b/ios/firebase_app_id_file.json @@ -0,0 +1,7 @@ +{ + "file_generated_by": "FlutterFire CLI", + "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", + "GOOGLE_APP_ID": "1:245204384533:ios:aeb233e55c5ddf7a9f871c", + "FIREBASE_PROJECT_ID": "prosapp-5747a", + "GCM_SENDER_ID": "245204384533" +} \ No newline at end of file diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart new file mode 100644 index 0000000..97619e5 --- /dev/null +++ b/lib/firebase_options.dart @@ -0,0 +1,84 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + return web; + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return android; + case TargetPlatform.iOS: + return ios; + case TargetPlatform.macOS: + return macos; + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions web = FirebaseOptions( + apiKey: 'AIzaSyCNpUV_4cMEL9QZx7NESXK7QAlRjRGwx_Y', + appId: '1:245204384533:web:1b8f0b4c1d9ae21d9f871c', + messagingSenderId: '245204384533', + projectId: 'prosapp-5747a', + authDomain: 'prosapp-5747a.firebaseapp.com', + storageBucket: 'prosapp-5747a.appspot.com', + ); + + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyBp7vsJvD6oXz0FORBLEeIELwId4a2onHQ', + appId: '1:245204384533:android:12920d0fe3ec9b999f871c', + messagingSenderId: '245204384533', + projectId: 'prosapp-5747a', + storageBucket: 'prosapp-5747a.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyDUhnkNkeEPkqcwVo5EWr63q3oEX6bDGic', + appId: '1:245204384533:ios:aeb233e55c5ddf7a9f871c', + messagingSenderId: '245204384533', + projectId: 'prosapp-5747a', + storageBucket: 'prosapp-5747a.appspot.com', + androidClientId: '245204384533-7p2j0go97da4gp062s7enop0ab8q7a7p.apps.googleusercontent.com', + iosClientId: '245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn.apps.googleusercontent.com', + iosBundleId: 'com.example.prosappco', + ); + + static const FirebaseOptions macos = FirebaseOptions( + apiKey: 'AIzaSyDUhnkNkeEPkqcwVo5EWr63q3oEX6bDGic', + appId: '1:245204384533:ios:aeb233e55c5ddf7a9f871c', + messagingSenderId: '245204384533', + projectId: 'prosapp-5747a', + storageBucket: 'prosapp-5747a.appspot.com', + androidClientId: '245204384533-7p2j0go97da4gp062s7enop0ab8q7a7p.apps.googleusercontent.com', + iosClientId: '245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn.apps.googleusercontent.com', + iosBundleId: 'com.example.prosappco', + ); +} diff --git a/lib/main.dart b/lib/main.dart index 675e337..1d3460e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,9 +3,14 @@ import 'package:prosappco/src/provider/google_sign.dart'; import 'package:prosappco/src/screens/login.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:provider/provider.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'firebase_options.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); runApp(const MyApp()); } diff --git a/lib/src/screens/login_email.dart b/lib/src/screens/login_email.dart index 5af65f1..53b0b00 100644 --- a/lib/src/screens/login_email.dart +++ b/lib/src/screens/login_email.dart @@ -2,7 +2,11 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.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'; class LoginEmailScreen extends StatefulWidget { @@ -12,6 +16,21 @@ class LoginEmailScreen extends StatefulWidget { State createState() => _LoginEmailScreenState(); } +final FirebaseAuth _auth = FirebaseAuth.instance; +final GoogleSignIn googleSignIn = GoogleSignIn(); +Future 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 _LoginEmailScreenState extends State { bool _obscureText = true; @@ -77,10 +96,23 @@ class _LoginEmailScreenState extends State { Padding( padding: EdgeInsets.only(bottom: 20), child: ElevatedButton( - onPressed: () { - final provider = Provider.of(context, - listen: false); - provider.googleLogin(); + onPressed: () async { + try { + final UserCredential userCredential = + 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( primary: Color(0xFF2BA4EC), diff --git a/lib/src/screens/welcome.dart b/lib/src/screens/welcome.dart index 8b13789..17d9bfd 100644 --- a/lib/src/screens/welcome.dart +++ b/lib/src/screens/welcome.dart @@ -1 +1,85 @@ +import 'package:flutter/material.dart'; +class WelcomeScreen extends StatefulWidget { + const WelcomeScreen({super.key}); + + @override + State createState() => _WelcomeScreenState(); +} + +class _WelcomeScreenState extends State { + @override + Widget build(BuildContext context) { + return SafeArea( + child: Scaffold( + resizeToAvoidBottomInset: false, + backgroundColor: Color(0xFFD6F4FF), + body: Stack( + children: [ + Container( + margin: const EdgeInsets.only(top: 130), + width: double.infinity, + height: 800, + decoration: const BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topRight: Radius.circular(50), + topLeft: Radius.circular(50))), + ), + Container( + margin: const EdgeInsets.only(top: 20, left: 30), + child: const Image( + image: AssetImage('images/logo_prosapp.png'), + width: 180, + height: 100, + ), + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 20), + margin: const EdgeInsets.only(top: 170), + child: Align( + alignment: Alignment.topCenter, + child: Text( + 'Bienvenido', + style: TextStyle( + color: Color(0xFF262626), + fontSize: 38.0, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 20), + margin: const EdgeInsets.only(top: 280, left: 50, right: 50), + child: Column(children: [ + Padding( + padding: const EdgeInsets.only(bottom: 40), + child: Center( + child: ElevatedButton( + onPressed: () {}, + child: Text( + 'Solicitar un servicio', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 18, + ), + ), + style: ElevatedButton.styleFrom( + primary: Color(0xFF2BA4EC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + elevation: 0, + minimumSize: Size(260, 60), + ), + )), + ), + ]), + ), + ], + ), + )); + } +} diff --git a/macos/Runner/GoogleService-Info.plist b/macos/Runner/GoogleService-Info.plist new file mode 100644 index 0000000..3b62a42 --- /dev/null +++ b/macos/Runner/GoogleService-Info.plist @@ -0,0 +1,36 @@ + + + + + CLIENT_ID + 245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.245204384533-nv7e2n7d4vj5kfkc55mlmiiju0ch2qhn + ANDROID_CLIENT_ID + 245204384533-7p2j0go97da4gp062s7enop0ab8q7a7p.apps.googleusercontent.com + API_KEY + AIzaSyDUhnkNkeEPkqcwVo5EWr63q3oEX6bDGic + GCM_SENDER_ID + 245204384533 + PLIST_VERSION + 1 + BUNDLE_ID + com.example.prosappco + PROJECT_ID + prosapp-5747a + STORAGE_BUCKET + prosapp-5747a.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:245204384533:ios:aeb233e55c5ddf7a9f871c + + \ No newline at end of file diff --git a/macos/firebase_app_id_file.json b/macos/firebase_app_id_file.json new file mode 100644 index 0000000..a4bc04d --- /dev/null +++ b/macos/firebase_app_id_file.json @@ -0,0 +1,7 @@ +{ + "file_generated_by": "FlutterFire CLI", + "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", + "GOOGLE_APP_ID": "1:245204384533:ios:aeb233e55c5ddf7a9f871c", + "FIREBASE_PROJECT_ID": "prosapp-5747a", + "GCM_SENDER_ID": "245204384533" +} \ No newline at end of file