Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:doctorradar/pages/doctorssubmit.dart';
- import 'dart:async';
- import 'package:doctorradar/pages/doctorsarea.dart';
- String docid;
- bool exist=false;
- final Controller = TextEditingController();
- bool enter=false;
- class LoginPage extends StatefulWidget {
- static String tag = 'login-page';
- @override
- LoginPageState createState() {
- return new LoginPageState();
- }
- }
- class LoginPageState extends State<LoginPage> {
- final DocumentReference documentReference =
- Firestore.instance.document("Doctors/$docid");
- StreamSubscription <DocumentSnapshot> subscription;
- Future<bool> doesNameAlreadyExist(String name, String collection,
- String Field) async {
- final QuerySnapshot result = await Firestore.instance
- .collection(collection)
- .where(Field, isEqualTo: name)
- .limit(1)
- .getDocuments();
- final List<DocumentSnapshot> documents = result.documents;
- final result1 = documents.length == 1;
- setState(() {
- exist = result1;
- });
- return result1;
- }
- @override
- Widget build(BuildContext context) {
- final Screensize = MediaQuery
- .of(context)
- .size;
- 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: 'Enter Your ID Code',
- 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: Screensize.width / 1.8,
- height: 42.0,
- onPressed: () {
- doesNameAlreadyExist(Controller.text, "Ids", "ID").then((value){
- if(value==true){
- subscription = documentReference.snapshots().listen((datasnapshot) {
- if(datasnapshot.exists){
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => DoctorsArea()),
- );
- }else if(!datasnapshot.exists){
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => Submit()),
- );
- }
- });
- } else if(value!=true){
- print("wrong creds");
- }
- });
- },
- color: Colors.lightBlueAccent,
- child: Text('Continue', 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: Screensize.height / 13.3),
- email,
- SizedBox(height: 8.0),
- SizedBox(height: 24.0),
- loginButton,
- FutureBuilder(
- future: doesNameAlreadyExist(Controller.text, "Ids", "ID"),
- 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("Your ID exists");
- }
- else
- return Text("Your ID does not exist");
- },
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement