1
1
import 'dart:async' ;
2
2
import 'dart:io' ;
3
3
import 'dart:math' as math;
4
- import "dart:math" show pi;
5
4
6
5
import 'package:flutter/material.dart' ;
7
6
import 'package:flutter/services.dart' ;
8
7
import 'package:flutter/widgets.dart' ;
9
8
import 'package:flutter_compass/flutter_compass.dart' ;
10
9
import 'package:flutter_map/plugin_api.dart' ;
11
- import 'package:latlong /latlong.dart' ;
10
+ import 'package:latlong2 /latlong.dart' ;
12
11
import 'package:location/location.dart' ;
13
12
import 'package:user_location/src/user_location_marker.dart' ;
14
13
import 'package:user_location/src/user_location_options.dart' ;
@@ -26,24 +25,24 @@ class MapsPluginLayer extends StatefulWidget {
26
25
27
26
class _MapsPluginLayerState extends State <MapsPluginLayer >
28
27
with TickerProviderStateMixin , WidgetsBindingObserver {
29
- LatLng _currentLocation;
30
- UserLocationMarker _locationMarker;
28
+ LatLng ? _currentLocation;
29
+ UserLocationMarker ? _locationMarker;
31
30
EventChannel _stream = EventChannel ('locationStatusStream' );
32
31
var location = Location ();
33
32
34
- bool mapLoaded;
35
- bool initialStateOfupdateMapLocationOnPositionChange;
33
+ late bool mapLoaded;
34
+ late bool initialStateOfupdateMapLocationOnPositionChange;
36
35
37
- double _direction;
36
+ double ? _direction;
38
37
39
- StreamSubscription <LocationData > _onLocationChangedStreamSubscription;
40
- StreamSubscription <CompassEvent > _compassStreamSubscription;
41
- StreamSubscription _locationStatusChangeSubscription;
38
+ StreamSubscription <LocationData >? _onLocationChangedStreamSubscription;
39
+ StreamSubscription <CompassEvent >? _compassStreamSubscription;
40
+ StreamSubscription ? _locationStatusChangeSubscription;
42
41
43
42
@override
44
43
void initState () {
45
44
super .initState ();
46
- WidgetsBinding .instance.addObserver (this );
45
+ WidgetsBinding .instance! .addObserver (this );
47
46
48
47
initialStateOfupdateMapLocationOnPositionChange =
49
48
widget.options.updateMapLocationOnPositionChange;
@@ -56,7 +55,7 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
56
55
57
56
@override
58
57
void dispose () {
59
- WidgetsBinding .instance.removeObserver (this );
58
+ WidgetsBinding .instance! .removeObserver (this );
60
59
_locationStatusChangeSubscription? .cancel ();
61
60
_onLocationChangedStreamSubscription? .cancel ();
62
61
_compassStreamSubscription? .cancel ();
@@ -140,11 +139,11 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
140
139
if (onValue.latitude == null || onValue.longitude == null ) {
141
140
_currentLocation = LatLng (0 , 0 );
142
141
} else {
143
- _currentLocation = LatLng (onValue.latitude, onValue.longitude);
142
+ _currentLocation = LatLng (onValue.latitude! , onValue.longitude! );
144
143
}
145
144
146
- var height = 20.0 * (1 - (onValue.accuracy / 100 ));
147
- var width = 20.0 * (1 - (onValue.accuracy / 100 ));
145
+ var height = 20.0 * (1 - (onValue.accuracy! / 100 ));
146
+ var width = 20.0 * (1 - (onValue.accuracy! / 100 ));
148
147
if (height < 0 || width < 0 ) {
149
148
height = 20 ;
150
149
width = 20 ;
@@ -160,15 +159,15 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
160
159
height: 20.0 ,
161
160
width: 20.0 ,
162
161
point:
163
- LatLng (_currentLocation.latitude, _currentLocation.longitude),
162
+ LatLng (_currentLocation! .latitude, _currentLocation! .longitude),
164
163
builder: (context) {
165
164
return Stack (
166
165
alignment: AlignmentDirectional .center,
167
166
children: < Widget > [
168
167
if (_direction != null && widget.options.showHeading)
169
168
ClipOval (
170
169
child: Transform .rotate (
171
- angle: _direction / 180 * math.pi,
170
+ angle: _direction! / 180 * math.pi,
172
171
child: CustomPaint (
173
172
size: Size (60.0 , 60.0 ),
174
173
painter: MyDirectionPainter (),
@@ -185,7 +184,7 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
185
184
width: 20 ,
186
185
decoration: BoxDecoration (
187
186
shape: BoxShape .circle,
188
- color: Colors .blue[300 ].withOpacity (0.7 ),
187
+ color: Colors .blue[300 ]! .withOpacity (0.7 ),
189
188
),
190
189
),
191
190
),
@@ -226,20 +225,22 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
226
225
setState (() {
227
226
mapLoaded = true ;
228
227
});
229
- animatedMapMove (_currentLocation, widget.options.defaultZoom,
228
+ animatedMapMove (_currentLocation! , widget.options.defaultZoom,
230
229
widget.options.mapController, this );
231
230
}
232
231
});
233
232
});
234
233
}
235
234
}
236
235
237
- void _moveMapToCurrentLocation ({double zoom}) {
236
+ void _moveMapToCurrentLocation ({double ? zoom}) {
238
237
if (_currentLocation != null ) {
239
238
animatedMapMove (
240
- LatLng (_currentLocation.latitude ?? LatLng (0 , 0 ),
241
- _currentLocation.longitude ?? LatLng (0 , 0 )),
242
- zoom ?? widget.map.zoom ?? 15 ,
239
+ LatLng (
240
+ _currentLocation! .latitude,
241
+ _currentLocation! .longitude,
242
+ ),
243
+ zoom ?? widget.map.zoom,
243
244
widget.options.mapController,
244
245
this ,
245
246
);
@@ -248,7 +249,7 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
248
249
249
250
void _handleLocationStatusChanges () {
250
251
printLog (_stream.toString ());
251
- bool _locationStatusChanged;
252
+ bool ? _locationStatusChanged;
252
253
if (_locationStatusChanged == null ) {
253
254
_locationStatusChangeSubscription =
254
255
_stream.receiveBroadcastStream ().listen ((onData) {
@@ -267,7 +268,7 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
267
268
268
269
void _handleCompassDirection () {
269
270
if (widget.options.showHeading) {
270
- _compassStreamSubscription = FlutterCompass .events.listen ((event) {
271
+ _compassStreamSubscription = FlutterCompass .events! .listen ((event) {
271
272
setState (() {
272
273
_direction = event.heading;
273
274
});
@@ -280,8 +281,8 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
280
281
if (widget.options.onLocationUpdate == null ) {
281
282
printLog ("Stream not provided" );
282
283
} else {
283
- widget.options.onLocationUpdate (
284
- LatLng (onValue.latitude, onValue.longitude),
284
+ widget.options.onLocationUpdate ! (
285
+ LatLng (onValue.latitude! , onValue.longitude! ),
285
286
onValue.speed,
286
287
);
287
288
}
@@ -313,7 +314,7 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
313
314
initialize ();
314
315
_moveMapToCurrentLocation (zoom: widget.options.defaultZoom);
315
316
if (widget.options.onTapFAB != null ) {
316
- widget.options.onTapFAB ();
317
+ widget.options.onTapFAB ! ();
317
318
}
318
319
},
319
320
child: widget.options.moveToCurrentLocationFloatingActionButton ??
@@ -381,11 +382,11 @@ class _MapsPluginLayerState extends State<MapsPluginLayer>
381
382
}
382
383
383
384
void forceMapUpdate () {
384
- var zoom = widget.options.mapController.zoom;
385
- widget.options.mapController.move (widget.options.mapController.center,
386
- widget.options.mapController.zoom + 0.000001 );
387
- widget.options.mapController
388
- .move (widget.options.mapController.center, zoom);
385
+ var zoom = widget.options.mapController! .zoom;
386
+ widget.options.mapController! .move (widget.options.mapController! .center,
387
+ widget.options.mapController! .zoom + 0.000001 );
388
+ widget.options.mapController!
389
+ .move (widget.options.mapController! .center, zoom);
389
390
}
390
391
}
391
392
0 commit comments