Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';
class MyLogin extends StatefulWidget {
@override
_MyLoginState createState() => _MyLoginState();
}
class _MyLoginState extends State<MyLogin> {
var authc = FirebaseAuth.instance;
String email;
String password;
bool sspin = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
title: Text('Login'),
),
body: ModalProgressHUD(
inAsyncCall: sspin,
child: Center(
child: Container(
width: 350,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Login Page',
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
SizedBox(
height: 60.0,
),
TextField(
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
email = value;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
labelText: 'EMAIL',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 20.0),
TextField(
obscureText: true,
onChanged: (value) {
password = value;
},
decoration: InputDecoration(
labelText: 'PASSWORD',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(
height: 20,
),
Container(
height: 40.0,
child: Material(
borderRadius: BorderRadius.circular(20.0),
shadowColor: Colors.greenAccent,
color: Colors.green,
elevation: 7.0,
child: GestureDetector(
onTap: () async {
setState(() {
sspin = true;
});
try {
var userSignin =
await authc.signInWithEmailAndPassword(
email: email, password: password);
print(userSignin);
if (userSignin != null) {
print("Logged In");
Navigator.pushNamed(context, "terminal");
setState(() {
sspin = false;
});
}
} catch (e) {
print(e);
}
},
child: Center(
child: Text(
'LOGIN',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
),
),
),
SizedBox(
height: 20,
),
Container(
color: Colors.transparent,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
color: Colors.transparent,
borderRadius: BorderRadius.circular(20.0)),
child: InkWell(
onTap: () {
Navigator.of(context).pushNamed('reg');
},
child: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
'Register',
style: TextStyle(
color: Colors.black,
fontFamily: 'Montserrat',
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
)
],
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment