I want to first check all the drivers nearby by selecting type of driver. and then get their distance from the client and than find the nearest driver among type and send the request, but my code is only getting the first driver in the list and sends the request thereafter.
void searchNearestDriver()
{
if(availableDrivers.length == 0)
{
cancelRideRequest();
resetApp();
noDriverFound();
return;
}
var driver = availableDrivers[0];
driversRef.child(driver.key).child("type").once().then((DataSnapshot snap) async
{
if(await snap.value != null)
{
String carType = snap.value.toString();
print("Driver from db " + carType);
if(carType == carRideType)
{
notifyDriver(driver);
availableDrivers.removeAt(0);
}
else
{
print(carRideType + " Cannot be found");
displayToastMessage(carRideType + " not available. Try again.", context);
}
}
else
{
displayToastMessage("No driver found. Try again.", context);
}
});
}