content: import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/material.dart';
  import 'package:flutterfire_samples/backend_actions/user_presence/screens/presence_page.dart';
  import 'package:flutterfire_samples/res/fire_assets.dart';
  
  import '../utils/authentication.dart';
  import '../utils/database.dart';
  
  class GoogleSignInButton extends StatefulWidget {
    const GoogleSignInButton({Key? key}) : super(key: key);
  
    @override
    GoogleSignInButtonState createState() => GoogleSignInButtonState();
  }
  
  class GoogleSignInButtonState extends State<GoogleSignInButton> {
    bool _isSigningIn = false;
    Database database = Database();
  
    @override
    Widget build(BuildContext context) {
      return Padding(
        padding: const EdgeInsets.only(bottom: 16.0),
        child: _isSigningIn
            ? const CircularProgressIndicator(
                valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
              )
            : OutlinedButton(
                style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.all(Colors.white),
                  shape: MaterialStateProperty.all(
                    RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(40),
                    ),
                  ),
                ),
                onPressed: () async {
                  setState(() {
                    _isSigningIn = true;
                  });
                  User? user =
                      await Authentication.signInWithGoogle(context: context);
  
                  setState(() {
                    _isSigningIn = false;
                  });
  
                  if (user != null) {
                    String userName = FirebaseAuth.instance.currentUser!.displayName!;
                    await database
                        .storeUserData(userName: userName)
                        .whenComplete(() => Navigator.of(context).pushReplacement(
                              MaterialPageRoute(
                                builder: (context) => PresencePage(
                                    userName: userName),
                              ),
                            ))
                        .catchError(
                          (e) => print('Error in storing data: $e'),
                        );
                  }
                },
                child: Padding(
                  padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: const [
                      Image(
                        image: AssetImage(FireAssets.googleLogo),
                        height: 35.0,
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 10),
                        child: Text(
                          'Sign in with Google',
                          style: TextStyle(
                            fontSize: 20,
                            color: Colors.black54,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
      );
    }
  }
  