getPTStopInfo method
Retrieve public-transport stop details when available.
This helper calls getPreviewExtendedData and converts the result to a PTStopInfo when the item belongs to CommonOverlayId.publicTransport.
Returns
- A PTStopInfo when available, otherwise null.
Implementation
Future<PTStopInfo?> getPTStopInfo() async {
final Completer<PTStopInfo?> completer = Completer<PTStopInfo?>();
if (isOfType(CommonOverlayId.publicTransport)) {
// Trigger the callback-based async operation
getPreviewExtendedData((GemError err, SearchableParameterList? params) {
if (params != null) {
// If successful, complete the Future with PTStopInfo
completer.complete(PTStopInfo.fromParameters(params));
} else {
// In case of an error or null params, complete with null
completer.complete(null);
}
});
} else {
// If the item isn't of the correct type, complete with null
completer.complete(null);
}
// Return the Future that will eventually be completed
return completer.future;
}