Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Commit 7a28e23

Browse files
author
sparmar
committed
Turn geoPoints non optional with blank list.
1 parent b758ef4 commit 7a28e23

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

example/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Future<void> main() async {
3232
print("GeoPoints are empty");
3333
return;
3434
}
35-
for (final gp in geoSerie.geoPoints!) {
35+
for (final gp in geoSerie.geoPoints) {
3636
print("${gp.name}: ${gp.latitude}/${gp.longitude}");
3737
}
3838
}

lib/src/models/geoserie.dart

+11-13
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ class GeoSerie {
6666
{required this.name,
6767
required this.type,
6868
this.id,
69-
this.geoPoints,
7069
this.surface,
7170
this.boundary,
72-
this.centroid});
71+
this.centroid,
72+
List<GeoPoint>? geoPoints})
73+
: this.geoPoints = geoPoints ?? <GeoPoint>[];
7374

7475
/// Name if the geoserie
7576
String name;
@@ -81,7 +82,7 @@ class GeoSerie {
8182
GeoSerieType type;
8283

8384
/// The list of [GeoPoint] in the serie
84-
List<GeoPoint>? geoPoints;
85+
List<GeoPoint> geoPoints;
8586

8687
/// The surface of a geometry
8788
num? surface;
@@ -100,12 +101,14 @@ class GeoSerie {
100101
: name = "${json["name"]}",
101102
id = int.parse("${json["id"]}"),
102103
surface = double.tryParse("${json["surface"]}"),
103-
type = _typeFromString("${json["type"]}");
104+
type = _typeFromString("${json["type"]}"),
105+
this.geoPoints = <GeoPoint>[];
104106

105107
/// Make a [GeoSerie] from name and serie type
106108
GeoSerie.fromNameAndType(
107109
{required this.name, required String typeStr, this.id})
108-
: type = _typeFromString(typeStr);
110+
: type = _typeFromString(typeStr),
111+
this.geoPoints = <GeoPoint>[];
109112

110113
/// [name] the name of the [GeoSerie]
111114
/// [typeStr] the type of the serie: group, line or polygon
@@ -128,10 +131,7 @@ class GeoSerie {
128131
/// Get a list of [LatLng] from this [GeoSerie]
129132
List<LatLng> toLatLng({bool ignoreErrors = false}) {
130133
final points = <LatLng>[];
131-
if (geoPoints == null) {
132-
return points;
133-
}
134-
for (final geoPoint in geoPoints!) {
134+
for (final geoPoint in geoPoints) {
135135
try {
136136
points.add(geoPoint.point);
137137
} catch (_) {
@@ -146,10 +146,8 @@ class GeoSerie {
146146
/// Convert to a geojson coordinates string
147147
String toGeoJsonCoordinatesString() {
148148
final coords = <String>[];
149-
if (geoPoints == null) {
150-
return "[]";
151-
}
152-
for (final geoPoint in geoPoints!) {
149+
150+
for (final geoPoint in geoPoints) {
153151
coords.add(geoPoint.toGeoJsonCoordinatesString());
154152
}
155153
return "[" + coords.join(",") + "]";

0 commit comments

Comments
 (0)