This commit is contained in:
@@ -63,6 +63,8 @@ class DefaultFirebaseOptions {
|
||||
messagingSenderId: '307701736370',
|
||||
projectId: 'traders-circuit',
|
||||
storageBucket: 'traders-circuit.appspot.com',
|
||||
iosClientId: '307701736370-il62k6tumpu03hnaiqkefj44494bvae6.apps.googleusercontent.com',
|
||||
iosBundleId: 'com.example.traderscircuit',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,16 +2,21 @@ import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:glassmorphism/glassmorphism.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:onesignal_flutter/onesignal_flutter.dart';
|
||||
import 'package:traderscircuit/Utils/Common/CustomTextFormField.dart';
|
||||
import 'package:traderscircuit/Utils/Common/commonBotton.dart';
|
||||
import 'package:traderscircuit/Utils/base_manager.dart';
|
||||
import 'package:traderscircuit/Utils/text.dart';
|
||||
import 'package:traderscircuit/Utils/utils.dart';
|
||||
import 'package:traderscircuit/resources/routes/route_name.dart';
|
||||
import 'package:traderscircuit/view/onBoarding/splashScreen1.dart';
|
||||
import 'package:traderscircuit/view_model/GoogleApi/google_api.dart';
|
||||
import '../../view_model/SendOtp/sendOtpObserver.dart';
|
||||
import '../../view_model/SendOtp/sendOtpbloc.dart';
|
||||
|
||||
@@ -31,6 +36,89 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
return !phoneNumberExpression.hasMatch(phoneNumber);
|
||||
}
|
||||
|
||||
_signInWithGooglecheck() async {
|
||||
// try {
|
||||
final GoogleSignIn googleSignIn = GoogleSignIn();
|
||||
await googleSignIn.signOut();
|
||||
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||
if (googleUser == null) {
|
||||
return;
|
||||
}
|
||||
final GoogleSignInAuthentication googleAuth =
|
||||
await googleUser.authentication;
|
||||
|
||||
print('googleAuth AccessToken ${googleAuth.accessToken}');
|
||||
|
||||
// Show loading dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// final status = await OneSignal.shared.getDeviceState();
|
||||
// final String? playerIdV = status?.userId;
|
||||
// Map<String, String> updata = {
|
||||
// "principal_source_xid": '3',
|
||||
// "access_token": '${googleAuth.accessToken}',
|
||||
// "player_id": playerIdV!,
|
||||
// };
|
||||
// // Call Google API
|
||||
// final data = await GoogleAPI(updata).googleApi();
|
||||
|
||||
// // Dismiss loading dialog
|
||||
// Navigator.of(context).pop();
|
||||
|
||||
// if (data.status == ResponseStatus.SUCCESS) {
|
||||
// // await global.setname();
|
||||
// // await global.getVar();
|
||||
|
||||
// Get.snackbar(
|
||||
// "Success!",
|
||||
// 'Google Sign In successful!',
|
||||
// duration: Duration(seconds: 2),
|
||||
// colorText: Colors.white,
|
||||
// backgroundColor: Colors.green,
|
||||
// margin: EdgeInsets.all(8),
|
||||
// snackStyle: SnackStyle.FLOATING,
|
||||
// snackPosition: SnackPosition.BOTTOM,
|
||||
// );
|
||||
|
||||
// Get.toNamed(RouteName.adddetails);
|
||||
// } else {
|
||||
// // Show an error message
|
||||
// Get.snackbar(
|
||||
// "Error!",
|
||||
// data.message,
|
||||
// duration: Duration(seconds: 2),
|
||||
// colorText: Colors.white,
|
||||
// backgroundColor: Colors.red,
|
||||
// margin: EdgeInsets.all(8),
|
||||
// snackStyle: SnackStyle.FLOATING,
|
||||
// snackPosition: SnackPosition.BOTTOM,
|
||||
// );
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print("Error during Google sign-in and API call: $e");
|
||||
// Get.snackbar(
|
||||
// "Error!",
|
||||
// 'Something went wrong, please try again!',
|
||||
// duration: Duration(seconds: 2),
|
||||
// colorText: Colors.white,
|
||||
// backgroundColor: Colors.red,
|
||||
// margin: EdgeInsets.all(8),
|
||||
// snackStyle: SnackStyle.FLOATING,
|
||||
// snackPosition: SnackPosition.BOTTOM,
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// final CounterBloc counterbloc = BlocProvider.of<CounterBloc>(context);
|
||||
@@ -353,52 +441,57 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
SizedBox(
|
||||
height: 15.h,
|
||||
),
|
||||
GlassmorphicContainer(
|
||||
width: double.infinity,
|
||||
height: 55.h,
|
||||
borderRadius: 8,
|
||||
linearGradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
const Color(0xFFffffff).withOpacity(0.1),
|
||||
const Color(0xFFFFFFFF).withOpacity(0.05),
|
||||
],
|
||||
stops: const [
|
||||
0.1,
|
||||
1,
|
||||
]),
|
||||
border: 0.5,
|
||||
blur: 10,
|
||||
borderGradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
const Color(0xff4A73FB).withOpacity(0.2),
|
||||
const Color(0xff4A73FB).withOpacity(0.2),
|
||||
const Color(0xff4A73FB).withOpacity(0.2),
|
||||
],
|
||||
stops: const [
|
||||
0.3,
|
||||
0.6,
|
||||
1,
|
||||
]),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/images/png/google.png",
|
||||
height: 30.h,
|
||||
width: 30.w,
|
||||
),
|
||||
SizedBox(
|
||||
width: 7.h,
|
||||
),
|
||||
text16W400(
|
||||
"Continue with google",
|
||||
),
|
||||
],
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_signInWithGooglecheck();
|
||||
},
|
||||
child: GlassmorphicContainer(
|
||||
width: double.infinity,
|
||||
height: 55.h,
|
||||
borderRadius: 8,
|
||||
linearGradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
const Color(0xFFffffff).withOpacity(0.1),
|
||||
const Color(0xFFFFFFFF).withOpacity(0.05),
|
||||
],
|
||||
stops: const [
|
||||
0.1,
|
||||
1,
|
||||
]),
|
||||
border: 0.5,
|
||||
blur: 10,
|
||||
borderGradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
const Color(0xff4A73FB).withOpacity(0.2),
|
||||
const Color(0xff4A73FB).withOpacity(0.2),
|
||||
const Color(0xff4A73FB).withOpacity(0.2),
|
||||
],
|
||||
stops: const [
|
||||
0.3,
|
||||
0.6,
|
||||
1,
|
||||
]),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/images/png/google.png",
|
||||
height: 30.h,
|
||||
width: 30.w,
|
||||
),
|
||||
SizedBox(
|
||||
width: 7.h,
|
||||
),
|
||||
text16W400(
|
||||
"Continue with google",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
30
lib/view_model/GoogleApi/google_api.dart
Normal file
30
lib/view_model/GoogleApi/google_api.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:traderscircuit/Utils/base_manager.dart';
|
||||
import 'package:traderscircuit/data/network/network_api_services.dart';
|
||||
|
||||
class GoogleAPI {
|
||||
GoogleAPI(this.data);
|
||||
var data;
|
||||
Future<ResponseData<dynamic>> googleApi() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final response = await NetworkApiServices().postApi(
|
||||
data,
|
||||
"auth/google-signin/",
|
||||
);
|
||||
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
//Map<String, dynamic> responseData = jsonDecode(response.data);
|
||||
if (response.data['success'] == true) {
|
||||
// await prefs.setString('token', response.data["data"]["access"]);
|
||||
// await prefs.setString('refreshToken', response.data["data"]["refresh"]);
|
||||
// await prefs.setBool('hasSignedInBefore', response.data["data"]["complete"]);
|
||||
print('signup: ${prefs.getString('token')}');
|
||||
} else {
|
||||
return ResponseData<dynamic>(
|
||||
response.data['message'], ResponseStatus.FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user