@@ -9,7 +9,7 @@ import 'package:flutter_map_example/widgets/number_of_items_slider.dart';
99import 'package:flutter_map_example/widgets/show_no_web_perf_overlay_snackbar.dart' ;
1010import 'package:latlong2/latlong.dart' ;
1111
12- const _maxCirclesCount = 20000 ;
12+ const _maxCirclesCount = 30000 ;
1313
1414/// On this page, [_maxCirclesCount] circles are randomly generated
1515/// across europe, and then you can limit them with a slider
@@ -21,15 +21,19 @@ class ManyCirclesPage extends StatefulWidget {
2121 const ManyCirclesPage ({super .key});
2222
2323 @override
24- ManyCirclesPageState createState () => ManyCirclesPageState ();
24+ State < ManyCirclesPage > createState () => _ManyCirclesPageState ();
2525}
2626
27- class ManyCirclesPageState extends State <ManyCirclesPage > {
28- double doubleInRange (Random source, num start, num end) =>
27+ class _ManyCirclesPageState extends State <ManyCirclesPage > {
28+ static double doubleInRange (Random source, num start, num end) =>
2929 source.nextDouble () * (end - start) + start;
30- List <CircleMarker > allCircles = [];
3130
3231 int numOfCircles = _maxCirclesCount ~ / 10 ;
32+ List <CircleMarker > allCircles = [];
33+
34+ bool useBorders = false ;
35+ bool useRadiusInMeters = false ;
36+ bool optimizeRadiusInMeters = true ;
3337
3438 @override
3539 void initState () {
@@ -39,12 +43,16 @@ class ManyCirclesPageState extends State<ManyCirclesPage> {
3943
4044 Future .microtask (() {
4145 final r = Random ();
42- for (var x = 0 ; x < _maxCirclesCount; x++ ) {
46+ for (double x = 0 ; x < _maxCirclesCount; x++ ) {
4347 allCircles.add (
4448 CircleMarker (
4549 point: LatLng (doubleInRange (r, 37 , 55 ), doubleInRange (r, - 9 , 30 )),
46- color: Colors .red,
50+ color: HSLColor .fromAHSL (1 , x % 360 , 1 , doubleInRange (r, 0.3 , 0.7 ))
51+ .toColor (),
4752 radius: 5 ,
53+ useRadiusInMeter: false ,
54+ borderStrokeWidth: 0 ,
55+ borderColor: Colors .black,
4856 ),
4957 );
5058 }
@@ -76,18 +84,106 @@ class ManyCirclesPageState extends State<ManyCirclesPage> {
7684 ),
7785 children: [
7886 openStreetMapTileLayer,
79- CircleLayer (circles: allCircles.take (numOfCircles).toList ()),
87+ CircleLayer (
88+ circles: allCircles.take (numOfCircles).toList (growable: false ),
89+ optimizeRadiusInMeters: optimizeRadiusInMeters,
90+ ),
8091 ],
8192 ),
8293 Positioned (
8394 left: 16 ,
8495 top: 16 ,
8596 right: 16 ,
86- child: NumberOfItemsSlider (
87- number: numOfCircles,
88- onChanged: (v) => setState (() => numOfCircles = v),
89- maxNumber: _maxCirclesCount,
90- itemDescription: 'Circle' ,
97+ child: RepaintBoundary (
98+ child: Column (
99+ children: [
100+ NumberOfItemsSlider (
101+ number: numOfCircles,
102+ onChanged: (v) => setState (() => numOfCircles = v),
103+ maxNumber: _maxCirclesCount,
104+ itemDescription: 'Circle' ,
105+ ),
106+ const SizedBox (height: 12 ),
107+ UnconstrainedBox (
108+ child: Container (
109+ decoration: BoxDecoration (
110+ color: Theme .of (context).colorScheme.surface,
111+ borderRadius: BorderRadius .circular (32 ),
112+ ),
113+ padding: const EdgeInsets .symmetric (
114+ vertical: 4 ,
115+ horizontal: 16 ,
116+ ),
117+ child: Row (
118+ children: [
119+ const Tooltip (
120+ message: 'Use Borders' ,
121+ child: Icon (Icons .circle_outlined),
122+ ),
123+ const SizedBox (width: 8 ),
124+ Switch .adaptive (
125+ value: useBorders,
126+ onChanged: (v) {
127+ allCircles = allCircles
128+ .map (
129+ (c) => CircleMarker (
130+ point: c.point,
131+ radius: c.radius,
132+ color: c.color,
133+ useRadiusInMeter: c.useRadiusInMeter,
134+ borderColor: c.borderColor,
135+ borderStrokeWidth: v ? 5 : 0 ,
136+ ),
137+ )
138+ .toList (growable: false );
139+ useBorders = v;
140+ setState (() {});
141+ },
142+ ),
143+ const SizedBox (width: 16 ),
144+ const Tooltip (
145+ message: 'Use Radius In Meters' ,
146+ child: Icon (Icons .straighten),
147+ ),
148+ const SizedBox (width: 8 ),
149+ Switch .adaptive (
150+ value: useRadiusInMeters,
151+ onChanged: (v) {
152+ allCircles = allCircles
153+ .map (
154+ (c) => CircleMarker (
155+ point: c.point,
156+ radius: v ? 25000 : 5 ,
157+ color: c.color,
158+ useRadiusInMeter: v,
159+ borderColor: c.borderColor,
160+ borderStrokeWidth: c.borderStrokeWidth,
161+ ),
162+ )
163+ .toList (growable: false );
164+ useRadiusInMeters = v;
165+ setState (() {});
166+ },
167+ ),
168+ const SizedBox (width: 16 ),
169+ const Tooltip (
170+ message: 'Optimise Meters Radius' ,
171+ child: Icon (Icons .speed_rounded),
172+ ),
173+ const SizedBox (width: 8 ),
174+ Switch .adaptive (
175+ value: optimizeRadiusInMeters,
176+ onChanged: useRadiusInMeters
177+ ? (v) =>
178+ setState (() => optimizeRadiusInMeters = v)
179+ : null ,
180+ ),
181+ ],
182+ ),
183+ ),
184+ ),
185+ ],
186+ ),
91187 ),
92188 ),
93189 if (! kIsWeb)
0 commit comments