22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import 'package:collection/collection.dart' ;
56import 'package:flutter/foundation.dart' show listEquals, VoidCallback;
67import 'package:flutter/material.dart' show Color, Colors;
78import 'package:meta/meta.dart' show immutable, required;
@@ -46,6 +47,7 @@ class Polygon {
4647 this .fillColor = Colors .black,
4748 this .geodesic = false ,
4849 this .points = const < LatLng > [],
50+ this .holes = const < List <LatLng >> [],
4951 this .strokeColor = Colors .black,
5052 this .strokeWidth = 10 ,
5153 this .visible = true ,
@@ -77,6 +79,14 @@ class Polygon {
7779 /// default; to form a closed polygon, the start and end points must be the same.
7880 final List <LatLng > points;
7981
82+ /// To create an empty area within a polygon, you need to use holes.
83+ /// To create the hole, the coordinates defining the hole path must be inside the polygon.
84+ ///
85+ /// The vertices of the holes to be cut out of polygon.
86+ ///
87+ /// Line segments of each points of hole are drawn inside polygon between consecutive hole points.
88+ final List <List <LatLng >> holes;
89+
8090 /// True if the marker is visible.
8191 final bool visible;
8292
@@ -106,6 +116,7 @@ class Polygon {
106116 Color fillColorParam,
107117 bool geodesicParam,
108118 List <LatLng > pointsParam,
119+ List <List <LatLng >> holesParam,
109120 Color strokeColorParam,
110121 int strokeWidthParam,
111122 bool visibleParam,
@@ -118,6 +129,7 @@ class Polygon {
118129 fillColor: fillColorParam ?? fillColor,
119130 geodesic: geodesicParam ?? geodesic,
120131 points: pointsParam ?? points,
132+ holes: holesParam ?? holes,
121133 strokeColor: strokeColorParam ?? strokeColor,
122134 strokeWidth: strokeWidthParam ?? strokeWidth,
123135 visible: visibleParam ?? visible,
@@ -154,6 +166,10 @@ class Polygon {
154166 json['points' ] = _pointsToJson ();
155167 }
156168
169+ if (holes != null ) {
170+ json['holes' ] = _holesToJson ();
171+ }
172+
157173 return json;
158174 }
159175
@@ -167,6 +183,7 @@ class Polygon {
167183 fillColor == typedOther.fillColor &&
168184 geodesic == typedOther.geodesic &&
169185 listEquals (points, typedOther.points) &&
186+ DeepCollectionEquality ().equals (holes, typedOther.holes) &&
170187 visible == typedOther.visible &&
171188 strokeColor == typedOther.strokeColor &&
172189 strokeWidth == typedOther.strokeWidth &&
@@ -183,4 +200,16 @@ class Polygon {
183200 }
184201 return result;
185202 }
203+
204+ List <List <dynamic >> _holesToJson () {
205+ final List <List <dynamic >> result = < List <dynamic >> [];
206+ for (final List <LatLng > hole in holes) {
207+ final List <dynamic > jsonHole = < dynamic > [];
208+ for (final LatLng point in hole) {
209+ jsonHole.add (point.toJson ());
210+ }
211+ result.add (jsonHole);
212+ }
213+ return result;
214+ }
186215}
0 commit comments