Skip to content

RangeError (index): Index out of range: no indices are valid: 0 on GeoJsonFeatureCollection.toJson if empty collection is returned from OpenRouteService #21

@miklcct

Description

@miklcct

GeoJsonFeatureCollection.toJson() does not work if the collection is empty from OpenRouteService.

import 'package:open_route_service/open_route_service.dart';

final openRouteService = OpenRouteService(apiKey: 'my_api_key');

void main() async {
  print((await openRouteService.geocodeAutoCompleteGet(text: 'skhfdkashfdkjashfdjs')).toJson());
}

Error:

Unhandled exception:
RangeError (index): Invalid value: Valid value range is empty: 0
#0      List.[] (dart:core-patch/growable_array.dart:264:36)
#1      GeoJsonFeatureCollection.toJson (package:open_route_service/src/models/geojson_feature_models.dart:57:15)
#2      main (file:///C:/Users/Michael/projects/test.dart:6:87)
<asynchronous suspension>

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions