Commit cc56f1b7 authored by GayaniPKarunaratne's avatar GayaniPKarunaratne

Done crud operations in Add location part

parent 218f8319
......@@ -38,7 +38,7 @@ getDate(date){
getTime(time){
this.time= time;
}
//---------------------------------------------Create Data-----------------------------------------------------
createData(){
print("object");
......@@ -59,6 +59,9 @@ createData(){
}
//---------------------------------------------Read Data-----------------------------------------------------
readData(){
DocumentReference documentReference = Firestore.instance.collection("RiskLocation").document(userName);
......@@ -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>();
//---------------------------------------------User Name-----------------------------------------------------
Widget _buildName(){
......@@ -210,33 +243,60 @@ Widget _buildTime(){
SizedBox(height: 100),
RaisedButton(
color: Colors.green,
child: Text(
'Submit',
style: TextStyle(color: Colors.green, fontSize: 18),
style: TextStyle(color: Colors.white, fontSize: 18),
),
onPressed: () {
if(!_formKey.currentState.validate()) {
return;
}
// _formKey.currentState.save();
// 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