search method

  1. @override
Future<List<Address>> search(
  1. String text
)
override

Implementation

@override
Future<List<Address>> search(String text) async {
  final places = await getPlaces(text);

  String findInContext(MapBoxPlace place, String key) {
    final contexts = place.context?.where((element) => element.id?.contains(key) ?? false) ?? [];
    return contexts.isEmpty ? '' : (contexts.first.text ?? '');
  }

  return [
    for (final place in places)
      Address(
        text: place.placeName,
        line1: (place.text ?? '') + ' ' + (place.addressNumber ?? ''),
        line2: '',
        city: findInContext(place, 'place'),
        country: findInContext(place, 'country'),
        state: findInContext(place, 'region'),
        postalCode: findInContext(place, 'postcode'),
      ),
  ];
}