Skip to content

Instantly share code, notes, and snippets.

@itsatifsiddiqui
Created May 16, 2019 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsatifsiddiqui/c0e292e61875a76cf204fabbf5c87dcf to your computer and use it in GitHub Desktop.
Save itsatifsiddiqui/c0e292e61875a76cf204fabbf5c87dcf to your computer and use it in GitHub Desktop.
LOGIN PAGE
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:providerlogin/model/user_repository.dart';
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0);
TextEditingController _email;
TextEditingController _password;
final _formKey = GlobalKey<FormState>();
final _key = GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
_email = TextEditingController(text: "");
_password = TextEditingController(text: "");
}
@override
Widget build(BuildContext context) {
final user = Provider.of<UserRepository>(context);
return Scaffold(
key: _key,
appBar: AppBar(
title: Text("Demo"),
),
body: Form(
key: _formKey,
child: Center(
child: ListView(
shrinkWrap: true,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: TextFormField(
controller: _email,
validator: (value) =>
(value.isEmpty) ? "Please Enter Email" : null,
style: style,
decoration: InputDecoration(
prefixIcon: Icon(Icons.email),
labelText: "Email",
border: OutlineInputBorder()),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: TextFormField(
controller: _password,
validator: (value) =>
(value.isEmpty) ? "Please Enter Password" : null,
style: style,
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock),
labelText: "Password",
border: OutlineInputBorder()),
),
),
user.status == Status.Authenticating
? Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Colors.red,
child: MaterialButton(
onPressed: () async {
if (_formKey.currentState.validate()) {
if (!await user.signIn(
_email.text, _password.text))
_key.currentState.showSnackBar(SnackBar(
content: Text("Something is wrong"),
));
}
},
child: Text(
"Sign In",
style: style.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
),
),
],
),
),
),
);
}
@override
void dispose() {
_email.dispose();
_password.dispose();
super.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment