I have added google sign in button to my login page. but when I CLICK IT its not working at all. I REFER this video for the implementation. how to resolve this. I'm struggling to find the error. appreciate your help on this. all the firebase parts are done according to the video instructions. there's no error to displaying. just button not working.
//google_sign_in.dart
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
class GoogleSignInProvider extends ChangeNotifier{
final googleSignIn =GoogleSignIn();
GoogleSignInAccount? _user;
GoogleSignInAccount get user => _user!;
Future googleLogin()async{
final googleUser= await googleSignIn.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(); //to update UI
}
}
//main.dart
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:lala_live/provider/google_sign_in.dart';
import 'package:lala_live/screens/login.dart';
import 'package:lala_live/screens/splashscreen.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:provider/provider.dart';
const bool USE_EMULATOR = false;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
if (USE_EMULATOR) {
_connectToFirebaseEmulator();
}
runApp(MyApp());
}
Future _connectToFirebaseEmulator() async {
final fireStorePort = "8080";
final authPort = 9099;
final localhost = Platform.isAndroid ? '10.0.2.2' : 'localhost';
FirebaseFirestore.instance.settings = Settings(
host: "$localhost:$fireStorePort",
sslEnabled: false,
persistenceEnabled: false,
);
await FirebaseAuth.instance.useAuthEmulator('http://$localhost:', authPort);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) => ChangeNotifierProvider(
create: (context)=> GoogleSignInProvider(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'Quicksand'),
home: FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (ctx, timer) => timer.connectionState == ConnectionState.done
? Login() //Screen to navigate to once the splashScreen is done.
: SplashScreen()),
),
);
}
//login.dart
Center(
child: SocialButton(
logo: 'asset/images/googleicon.png',
height: widgetheight,
width: width / 4,
text: 'Google',
onPressed: () {
final provider = Provider.of<GoogleSignInProvider>(context,listen:false);
provider.googleLogin();
},
color: containergrey)),
],
),