chuyentt / geojson_vi

An Open-Source Dart and Flutter Library for Efficiently Handling GeoJSON Data in Compliance with RFC 7946
https://pub.dev/packages/geojson_vi
MIT License
15 stars 10 forks source link

GeometryCollection.bbox crashes when geometries is empty list #15

Closed barbalex closed 2 years ago

barbalex commented 3 years ago

I have this code which runs after a user tapped on a polygon to delete it (and after the code that removes the polygon from the geometry collection):

print(
    'onTap, geomCollection: $geomCollection, type: ${geomCollection.runtimeType}');
List<double>? bbox = geomCollection.bbox;

which logs:

I/flutter (30452): onTap, geomCollection: GeometryCollection(geometries: []), type: GeoJSONGeometryCollection
E/flutter (30452): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Bad state: No element
E/flutter (30452): #0      List.first (dart:core-patch/growable_array.dart:332:5)
E/flutter (30452): #1      GeoJSONGeometryCollection.bbox
package:geojson_vi/…/classes/geometry_collection.dart:27
E/flutter (30452): #2      _MapMapWidgetState.build.<anonymous closure>
package:capturing/…/map/map.dart:419
E/flutter (30452): #3      MapGestureMixin.handleTap
package:flutter_map/…/gestures/gestures.dart:513
E/flutter (30452): #4      _TapPositionDetectorState._postCallback
package:positioned_tap_detector_2/positioned_tap_detector_2.dart:128
E/flutter (30452): #5      _TapPositionDetectorState._onTimeout
package:positioned_tap_detector_2/positioned_tap_detector_2.dart:74
E/flutter (30452): #6      _invokeErrorHandler (dart:async/async_error.dart:45:24)
E/flutter (30452): #7      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:272:9)
E/flutter (30452): #8      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:157:13)
E/flutter (30452): #9      _rootRunBinary (dart:async/zone.dart:1378:47)
E/flutter (30452): #10     _CustomZone.runBinary (dart:async/zone.dart:1272:19)
E/flutter (30452): #11     _CustomZone.runBinaryGuarded (dart:async/zone.dart:1178:7)
E/flutter (30452): #12     _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:360:15)
E/flutter (30452): #13     _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:378:16)
E/flutter (30452): #14     _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:280:7)
E/flutter (30452): #15     _SyncStreamControllerDispatch._sendError (dart:async/stream_controller.dart:737:19)
E/flutter (30452): #16     _StreamController._addError (dart:async/stream_controller.dart:615:7)
E/flutter (30452): #17     _StreamController.addError (dart:async/stream_controller.dart:569:5)
E/flutter (30452): #18     Stream.timeout.<anonymous closure> (dart:async/stream.dart:1505:20)
E/flutter (30452): #19     _rootRun (dart:async/zone.dart:1354:13)
E/flutter (30452): #20     _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (30452): #21     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1186:23)
E/flutter (30452): #22     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (30452): #23     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
E/flutter (30452): #24     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
E/flutter (30452): #25     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Wouldn't it make more sense if bbox returned an empty array?

chuyentt commented 2 years ago

Thank you,

I've just released geojson_vi 2.0.6