Commit cc56f1b7 authored by GayaniPKarunaratne's avatar GayaniPKarunaratne

Done crud operations in Add location part

parent 218f8319
...@@ -38,7 +38,7 @@ getDate(date){ ...@@ -38,7 +38,7 @@ getDate(date){
getTime(time){ getTime(time){
this.time= time; this.time= time;
} }
//---------------------------------------------Create Data-----------------------------------------------------
createData(){ createData(){
print("object"); print("object");
...@@ -59,6 +59,9 @@ createData(){ ...@@ -59,6 +59,9 @@ createData(){
} }
//---------------------------------------------Read Data-----------------------------------------------------
readData(){ readData(){
DocumentReference documentReference = Firestore.instance.collection("RiskLocation").document(userName); DocumentReference documentReference = Firestore.instance.collection("RiskLocation").document(userName);
...@@ -72,6 +75,36 @@ readData(){ ...@@ -72,6 +75,36 @@ readData(){
}); });
} }
//---------------------------------------------Update Data-----------------------------------------------------
updateData(){
print("object");
DocumentReference documentReference = Firestore.instance.collection("RiskLocation").document(userName);
Map<String, dynamic> locations ={
"userName": userName,
"phoneNumber": phoneNumber,
"riskLocation": riskLocation,
"hotelName": hotelName,
"date": date,
"time": time
};
documentReference.setData(locations).whenComplete(() {
print("$userName Updated");
});
}
//---------------------------------------------Delete Data-----------------------------------------------------
deleteData(){
DocumentReference documentReference = Firestore.instance.collection("RiskLocation").document(userName);
documentReference.delete().whenComplete((){
print("$userName Deleted");
});
}
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
//---------------------------------------------User Name----------------------------------------------------- //---------------------------------------------User Name-----------------------------------------------------
Widget _buildName(){ Widget _buildName(){
...@@ -210,33 +243,60 @@ Widget _buildTime(){ ...@@ -210,33 +243,60 @@ Widget _buildTime(){
SizedBox(height: 100), SizedBox(height: 100),
RaisedButton( RaisedButton(
color: Colors.green,
child: Text( child: Text(
'Submit', 'Submit',
style: TextStyle(color: Colors.green, fontSize: 18), style: TextStyle(color: Colors.white, fontSize: 18),
), ),
onPressed: () { onPressed: () {
if(!_formKey.currentState.validate()) { if(!_formKey.currentState.validate()) {
return; return;
} }
// _formKey.currentState.save(); createData();
// print(_fName); } ,
// print(_lName); ),
// print(_age);
// print(_address);
// print(_nic);
// print(_phoneNumber);
// print(_riskLocation);
// print(_hotelName);
// print(_date);
// print(_time);
createData(); RaisedButton(
color: Colors.blue,
child: Text(
'View',
style: TextStyle(color: Colors.white, fontSize: 18),
),
onPressed: () {
readData();
} , } ,
) ),
RaisedButton(
color: Colors.yellowAccent[700],
child: Text(
'Update',
style: TextStyle(color: Colors.white, fontSize: 18),
),
onPressed: () {
updateData();
} ,
),
RaisedButton(
color: Colors.red,
child: Text(
'Delete',
style: TextStyle(color: Colors.white, fontSize: 18),
),
onPressed: () {
deleteData();
} ,
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment