Skip to content

Instantly share code, notes, and snippets.

@cankush625
Created October 28, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cankush625/dbcee9f656a759658de61e864762bd89 to your computer and use it in GitHub Desktop.
Save cankush625/dbcee9f656a759658de61e864762bd89 to your computer and use it in GitHub Desktop.
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
var authc = FirebaseAuth.instance;
String email;
String password;
bool sspin = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Login'),
),
body: ModalProgressHUD(
inAsyncCall: sspin,
child: Center(
child: Container(
width: 300,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
email = value;
},
decoration: InputDecoration(
hintText: "Enter Email",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
SizedBox(
height: 10,
),
TextField(
obscureText: true,
onChanged: (value) {
password = value;
},
decoration: InputDecoration(
hintText: "Enter Password",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
SizedBox(
height: 10,
),
Material(
color: Colors.lightBlueAccent,
borderRadius: BorderRadius.circular(10),
elevation: 10,
child: MaterialButton(
minWidth: 200,
height: 40,
child: Text('Login'),
onPressed: () async {
setState(() {
sspin = true;
});
try {
var userSignin = await authc.signInWithEmailAndPassword(
email: email, password: password);
print(userSignin);
if (userSignin != null) {
Navigator.pushNamed(context, "home");
setState(() {
sspin = false;
});
}
} catch (e) {
print(e);
}
},
),
),
],
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment