content: import 'package:firebase_auth/firebase_auth.dart';
  import 'package:firebase_core/firebase_core.dart';
  import 'package:flutter/material.dart';
  import 'package:flutterfire_samples/firebase_options.dart';
  import 'package:flutterfire_samples/res/custom_colors.dart';
  import 'package:flutterfire_samples/authentication/phone_sign_in/widgets/sign_in_form.dart';
  
  import 'user_info_screen.dart';
  
  class SignInScreen extends StatefulWidget {
    const SignInScreen({Key? key}) : super(key: key);
  
    @override
    SignInScreenState createState() => SignInScreenState();
  }
  
  class SignInScreenState extends State<SignInScreen> {
    late final FocusNode _phoneNumberFocusNode;
  
    Future<FirebaseApp> _initializeFirebase() async {
      FirebaseApp firebaseApp = await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
  
      User? user = FirebaseAuth.instance.currentUser;
  
      if (user != null) {
        if (!mounted) return firebaseApp;
        Navigator.of(context).pushReplacement(
          MaterialPageRoute(
            builder: (context) => UserInfoScreen(
              user: user,
            ),
          ),
        );
      }
  
      return firebaseApp;
    }
  
    @override
    void initState() {
      _phoneNumberFocusNode = FocusNode();
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return GestureDetector(
        onTap: () {
          _phoneNumberFocusNode.unfocus();
        },
        child: Scaffold(
          backgroundColor: Palette.firebaseNavy,
          body: SafeArea(
            child: Stack(
              children: [
                Padding(
                  padding: const EdgeInsets.only(
                    left: 16.0,
                    right: 16.0,
                    bottom: 20.0,
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Row(),
                      Expanded(
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Flexible(
                              flex: 1,
                              child: Image.asset(
                                'assets/firebase_logo.png',
                                height: 160,
                              ),
                            ),
                            const SizedBox(height: 20),
                            const Text(
                              'FlutterFire',
                              style: TextStyle(
                                color: Palette.firebaseYellow,
                                fontSize: 40,
                              ),
                            ),
                            const Text(
                              'Authentication',
                              style: TextStyle(
                                color: Palette.firebaseOrange,
                                fontSize: 40,
                              ),
                            ),
                          ],
                        ),
                      ),
                      FutureBuilder(
                        future: _initializeFirebase(),
                        builder: (context, snapshot) {
                          if (snapshot.hasError) {
                            return const Text('Error initializing Firebase');
                          } else if (snapshot.connectionState ==
                              ConnectionState.done) {
                            return SignInForm(
                              phoneNumberFocusNode: _phoneNumberFocusNode,
                            );
                          }
                          return const CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation<Color>(
                              Palette.firebaseOrange,
                            ),
                          );
                        },
                      ),
                    ],
                  ),
                ),
                Align(
                  alignment: Alignment.topLeft,
                  child: Padding(
                    padding: const EdgeInsets.only(top: 8.0, left: 8.0),
                    child: Container(
                      decoration: BoxDecoration(
                        color: Colors.black26,
                        borderRadius: BorderRadius.circular(30.0),
                      ),
                      child: const BackButton(),
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      );
    }
  }
  