mirrored_repositories/firebase-chatapp/lib

   
import 'package:chatapp/constants.dart';
import 'package:chatapp/presentation/chat_screen.dart';
import 'package:chatapp/widgets/custom_button.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';

class LoginScreen extends StatefulWidget {
  static const String id  = 'login_screen';
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
FirebaseAuth _auth = FirebaseAuth.instance;
late String email;
late String password;

bool showSpinner = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: ModalProgressHUD(
        inAsyncCall: showSpinner,
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 24.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Flexible(
                child: Hero(
                  tag: 'logo',
                  child: Container(
                    height: 200.0,
                    child: Image.asset('images/logo.png'),
                  ),
                ),
              ),
              SizedBox(
                height: 48.0,
              ),
              TextField(
                keyboardType: TextInputType.emailAddress,
                textAlign: TextAlign.center,
                onChanged: (value) {
                  email = value;
                  //Do something with the user input.
                },
                decoration: kInputDecoration),
              
              SizedBox(
                height: 8.0,
              ),
              TextField(
                 textAlign: TextAlign.center,
                obscureText: true,
                onChanged: (value) {
              
                  password = value;
                },
                decoration: kInputDecoration.copyWith(hintText: 'Enter your password'),
              ),
              SizedBox(
                height: 24.0,
              ),
             CustomButton(text: 'Log In', color: Colors.lightBlueAccent, onPressed: ()async{
               setState(() {
                 showSpinner = true;
               });
               
               try{
                 UserCredential userCredential = await _auth.signInWithEmailAndPassword(email: email, password: password);
                 if (userCredential != null){Navigator.pushReplacementNamed(context, ChatScreen.id);}
      
               }
               catch(e){print(e);}
             }),
            ],
          ),
        ),
      ),
    );
  }
}