I wanted to do an update function where user can input a tracking number and update a parcel data. The doc(trackingnumber) will be taken from user inputted trackingnumber before getting the snapshot from StreamBuilder. After the button is clicked(gesturedetector), the function will compare the snapshot data with user input before the update is executed. I'm still new to flutter. Here's my effort so far.
GestureDetector(
onTap: () {
StreamBuilder<ParcelModel>(
stream:
ParcelService(trackingNumber: trackingNumberController.text)
.singleparcel,
builder: (context, snapshot) {
ParcelModel? singleparcel = snapshot.data;
return GestureDetector(
onTap: () async {
if (singleparcel?.parcelNumber ==
int.parse(parcelNumberController.text) &&
singleparcel?.trackingNumber ==
trackingNumberController.text) {
await ParcelService(
trackingNumber: trackingNumberController.text)
.executeRetrieveParcel(
trackingNumberController.text,
retrieverNameController.text,
studentIDController.text,
retrieverPhoneController.text,
int.parse(parcelNumberController.text),
singleparcel?.studentName,
singleparcel?.dateArrived);
Fluttertoast.showToast(
msg: "Parcel retrieved successfully :)");
setState(() => loading = false);
} else if (singleparcel?.parcelNumber !=
int.parse(parcelNumberController.text)) {
Fluttertoast.showToast(msg: "Incorrect Parcel Number!");
setState(() => loading = false);
} else {
setState(() => loading = false);
}
});
});
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Color(0xffA97575),
borderRadius: BorderRadius.circular(12),
),
child: Center(
child: Text(
'Update & Notify Student',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
),
),