content: import 'dart:developer';
  
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/material.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'commonComponents/customCard.dart';
  
  class HomePage extends StatefulWidget {
    HomePage({Key key, this.title, this.uid}) : super(key: key); //update this to include the uid in the constructor
    final String title;
    final String uid; //include this
  
    @override
    _HomePageState createState() => _HomePageState();
  }
  
  class _HomePageState extends State<HomePage> {
    TextEditingController taskTitleInputController;
    TextEditingController taskDescripInputController;
    FirebaseUser currentUser;
  
    @override
    initState() {
      taskTitleInputController = new TextEditingController();
      taskDescripInputController = new TextEditingController();
      this.getCurrentUser();
      super.initState();
    }
  
    void getCurrentUser() async {
      currentUser = await FirebaseAuth.instance.currentUser();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          actions: <Widget>[
            FlatButton(
              child: Text("Log Out"),
              textColor: Colors.white,
              onPressed: () {
                FirebaseAuth.instance
                    .signOut()
                    .then((result) =>
                        Navigator.pushReplacementNamed(context, "/login"))
                    .catchError((err) => print(err));
              },
            )
          ],
        ),
        body: Center(
          child: Container(
              padding: const EdgeInsets.all(20.0),
              child: StreamBuilder<QuerySnapshot>(
                stream: Firestore.instance
                    .collection("users")
                    .document(widget.uid)
                    .collection('tasks')
                    .snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (snapshot.hasError)
                    return new Text('Error: ${snapshot.error}');
                  switch (snapshot.connectionState) {
                    case ConnectionState.waiting:
                      return new Text('Loading...');
                    default:
                      return new ListView(
                        children: snapshot.data.documents
                            .map((DocumentSnapshot document) {
                          return new CustomCard(
                            title: document['title'],
                            description: document['description'],
                          );
                        }).toList(),
                      );
                  }
                },
              )),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _showDialog,
          tooltip: 'Add',
          child: Icon(Icons.add),
        ),
      );
    }
  
    _showDialog() async {
      await showDialog<String>(
        context: context,
        child: AlertDialog(
          contentPadding: const EdgeInsets.all(16.0),
          content: Column(
            children: <Widget>[
              Text("Please fill all fields to create a new task"),
              Expanded(
                child: TextField(
                  autofocus: true,
                  decoration: InputDecoration(labelText: 'Task Title*'),
                  controller: taskTitleInputController,
                ),
              ),
              Expanded(
                child: TextField(
                  decoration: InputDecoration(labelText: 'Task Description*'),
                  controller: taskDescripInputController,
                ),
              )
            ],
          ),
          actions: <Widget>[
            FlatButton(
                child: Text('Cancel'),
                onPressed: () {
                  taskTitleInputController.clear();
                  taskDescripInputController.clear();
                  Navigator.pop(context);
                }),
            FlatButton(
                child: Text('Add'),
                onPressed: () {
                  if (taskDescripInputController.text.isNotEmpty &&
                      taskTitleInputController.text.isNotEmpty) {
                    Firestore.instance
                        .collection("users")
                        .document(widget.uid)
                        .collection('tasks')
                        .add({
                          "title": taskTitleInputController.text,
                          "description": taskDescripInputController.text
                        })
                        .then((result) => {
                              Navigator.pop(context),
                              taskTitleInputController.clear(),
                              taskDescripInputController.clear(),
                            })
                        .catchError((err) => print(err));
                  }
                })
          ],
        ),
      );
    }
  }
  