flutter_map
flutter_map copied to clipboard
[BUG] Failure to calculate `LatLngBounds.center` for some points
What is the bug?
When an object of class LatLngBounds is created with some values, the subsequent call of the getter "center" on the object causes an AssertionError
How can we reproduce it?
In the real-world scenario, we're using flutter_map_marker_cluster library, which is trying to draw a cluster marker, during this process the "center" getter is called, and the whole layer rendering fails with an AssertionError.
Here is a small test to reproduce the problem:
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:test/test.dart';
void main() {
group('LatLngBounds', () {
test('should calculate center point #1', () async {
final bounds = LatLngBounds(const LatLng(-77.45, -171.16), const LatLng(46.64, 25.88));
final center = bounds.center;
expect(center.latitude, greaterThanOrEqualTo(-90));
expect(center.latitude, lessThanOrEqualTo(90));
expect(center.longitude, greaterThanOrEqualTo(-180));
expect(center.longitude, lessThanOrEqualTo(180));
});
test('should calculate center point #2', () async {
final bounds = LatLngBounds(const LatLng(-0.87, -179.86), const LatLng(84.92, 23.86));
final center = bounds.center;
expect(center.latitude, greaterThanOrEqualTo(-90));
expect(center.latitude, lessThanOrEqualTo(90));
expect(center.longitude, greaterThanOrEqualTo(-180));
expect(center.longitude, lessThanOrEqualTo(180));
});
});
}
and the result is:
dart:core _AssertionError._throwNew
package:latlong2/latlong/LatLng.dart 34:16 new LatLng
package:flutter_map/src/geo/latlng_bounds.dart 121:12 LatLngBounds.center
test/latlng_bounds_test.dart 9:29 main.<fn>.<fn>
'package:latlong2/latlong/LatLng.dart': Failed assertion: line 34 pos 16: 'longitude >= -180 && longitude <= 180': is not true.
dart:core _AssertionError._throwNew
package:latlong2/latlong/LatLng.dart 34:16 new LatLng
package:flutter_map/src/geo/latlng_bounds.dart 121:12 LatLngBounds.center
test/latlng_bounds_test.dart 17:29 main.<fn>.<fn>
'package:latlong2/latlong/LatLng.dart': Failed assertion: line 34 pos 16: 'longitude >= -180 && longitude <= 180': is not true.
Do you have a potential solution?
No response
Platforms
flutter_map-5.0.0
Severity
Erroneous: Prevents normal functioning and causes errors in the console