search static method

TaskHandler? search(
  1. String filter,
  2. Landmark parent,
  3. AddressDetailLevel detailLevel,
  4. void onComplete(
    1. GemError err,
    2. List<Landmark> landmarks
    ),
)

Search for address items under a specified parent landmark.

The search starts at parent and returns items matching filter at the requested detailLevel. If parent is the default landmark, only AddressDetailLevel.country can be searched. The search will return results according to the session preferences (for example, maximum matches and fuzzy matching).

This function should be used to progressively drill down the address hierarchy by using results from one search as the parent for the next level.

Parameters

  • filter: The text filter to apply. If empty, all items at the requested level are returned (subject to preferences limits).
  • parent: The landmark to use as the starting point for the search.
  • detailLevel: The detail level to search for (see AddressDetailLevel). Use getNextAddressDetailLevel to determine valid levels for a given parent.
  • onComplete: Callback invoked when the search completes. It provides:
    • err: The resulting GemError code for the operation.
    • landmarks: List of matching landmarks (empty on failure).

Returns

Also see:

Implementation

static TaskHandler? search(
  final String filter,
  final Landmark parent,
  final AddressDetailLevel detailLevel,
  final void Function(GemError err, List<Landmark> landmarks) onComplete,
) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
  final LandmarkList results = LandmarkList();

  progListener.registerOnCompleteWithData((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(progListener.id);

    if (err == GemError.success.code || err == GemError.reducedResult.code) {
      onComplete(GemErrorExtension.fromCode(err), results.toList());
    } else {
      onComplete(GemErrorExtension.fromCode(err), <Landmark>[]);
    }
  });

  final OperationResult resultString = staticMethod(
    'GuidedAddressSearchService',
    'search',
    args: <String, dynamic>{
      'results': results.pointerId,
      'parent': parent.pointerId,
      'filter': filter,
      'detailToSearch': detailLevel.id,
      'progress': progListener.id,
    },
  );

  final int errorCode = resultString['result'];

  if (errorCode != GemError.success.code) {
    onComplete(GemErrorExtension.fromCode(errorCode), <Landmark>[]);
    return null;
  }

  return TaskHandlerImpl(progListener.id);
}