Created
August 8, 2018 14:32
-
-
Save diegoveloper/858b5eb773ea1079b5668ef8a9c967e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:cloud_firestore/cloud_firestore.dart'; | |
import 'package:doctorradar/pages/doctorssubmit.dart'; | |
import 'dart:async'; | |
int i=1; | |
String name='2'; | |
bool exist=false; | |
final Controller = TextEditingController(); | |
class LoginPage extends StatefulWidget { | |
static String tag = 'login-page'; | |
@override | |
_LoginPageState createState() => new _LoginPageState(); | |
} | |
class _LoginPageState extends State<LoginPage> { | |
@override | |
void dispose() { | |
// Clean up the controller when the Widget is disposed | |
Controller.dispose(); | |
super.dispose(); | |
} | |
Future<bool> doesNameAlreadyExist(String name) async { | |
final QuerySnapshot result = await Firestore.instance | |
.collection('IDS') | |
.where('ID$i', isEqualTo: name) | |
.limit(1) | |
.getDocuments(); | |
final List<DocumentSnapshot> documents = result.documents; | |
final result = documents.length == 1; | |
setState(() { | |
exist=result; | |
}); | |
return result; | |
} | |
@override | |
Widget build(BuildContext context) { | |
final logo = Hero( | |
tag: 'hero', | |
child: CircleAvatar( | |
backgroundColor: Colors.transparent, | |
radius: 48.0, | |
child: Image.asset('lib/images/logo.png'), | |
), | |
); | |
final email = TextFormField( | |
keyboardType: TextInputType.emailAddress, | |
autofocus: false, | |
decoration: InputDecoration( | |
hintText: 'Your ID', | |
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), | |
border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)), | |
), | |
controller: Controller, | |
); | |
final loginButton = Padding( | |
padding: EdgeInsets.symmetric(vertical: 16.0), | |
child: Material( | |
borderRadius: BorderRadius.circular(30.0), | |
shadowColor: Colors.lightBlueAccent.shade100, | |
elevation: 5.0, | |
child: MaterialButton( | |
minWidth: 200.0, | |
height: 42.0, | |
onPressed: () { | |
setState(() { | |
name=Controller.text; | |
}); | |
if(exist==true){ | |
Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => Submit()), | |
); | |
} else if(exist==false){ | |
print("Wrong Credintials"); | |
} | |
}, | |
color: Colors.lightBlueAccent, | |
child: Text('Log In', style: TextStyle(color: Colors.white)), | |
), | |
), | |
); | |
return Scaffold( | |
backgroundColor: Colors.white, | |
body: Center( | |
child: ListView( | |
shrinkWrap: true, | |
padding: EdgeInsets.only(left: 24.0, right: 24.0), | |
children: <Widget>[ | |
logo, | |
SizedBox(height: 48.0), | |
email, | |
SizedBox(height: 8.0), | |
SizedBox(height: 24.0), | |
loginButton, | |
FutureBuilder( | |
future: doesNameAlreadyExist(name), | |
builder: (context, AsyncSnapshot<bool> result) { | |
if (!result.hasData) | |
return Container(); // future still needs to be finished (loading) | |
if (result.data){ // result.data is the returned bool from doesNameAlreadyExists | |
return Text('A company called "Nova" already exists.'); | |
} | |
else | |
return Text('Your ID does Not exist'); | |
}, | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment