diff --git a/example/lib/main.dart b/example/lib/main.dart index 331349a..cf12ebc 100755 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:user_location/user_location.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong2/latlong.dart'; +import 'package:latlong/latlong.dart'; void main() => runApp(MyApp()); @@ -21,10 +21,10 @@ class MyApp extends StatelessWidget { } class HomePage extends StatelessWidget { - final MapController mapController = MapController(); - final List markers = []; - final StreamController markerlocationStream = StreamController(); - late UserLocationOptions userLocationOptions; + MapController mapController = MapController(); + List markers = []; + StreamController markerlocationStream = StreamController(); + UserLocationOptions userLocationOptions; onTapFAB() { print('Callback function has been called'); @@ -42,7 +42,7 @@ class HomePage extends StatelessWidget { context: context, mapController: mapController, markers: markers, - onLocationUpdate: (LatLng pos, double? speed) => + onLocationUpdate: (LatLng pos, double speed) => print("onLocationUpdate ${pos.toString()}"), updateMapLocationOnPositionChange: false, showMoveToCurrentLocationFloatingActionButton: true, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 42c6adb..b09e499 100755 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,7 +5,7 @@ publish_to: 'none' version: 1.0.0 environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.1.0 <3.0.0" dependencies: flutter: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 0f66d35..0de3195 100755 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { expect( find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data!.startsWith('Running on:'), + widget.data.startsWith('Running on:'), ), findsOneWidget, ); diff --git a/lib/src/user_location_layer.dart b/lib/src/user_location_layer.dart index f9a3386..d8d003f 100755 --- a/lib/src/user_location_layer.dart +++ b/lib/src/user_location_layer.dart @@ -1,13 +1,14 @@ import 'dart:async'; import 'dart:io'; import 'dart:math' as math; +import "dart:math" show pi; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_compass/flutter_compass.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong2/latlong.dart'; +import 'package:latlong/latlong.dart'; import 'package:location/location.dart'; import 'package:user_location/src/user_location_marker.dart'; import 'package:user_location/src/user_location_options.dart'; @@ -25,24 +26,24 @@ class MapsPluginLayer extends StatefulWidget { class _MapsPluginLayerState extends State with TickerProviderStateMixin, WidgetsBindingObserver { - LatLng? _currentLocation; - UserLocationMarker? _locationMarker; + LatLng _currentLocation; + UserLocationMarker _locationMarker; EventChannel _stream = EventChannel('locationStatusStream'); var location = Location(); - late bool mapLoaded; - late bool initialStateOfupdateMapLocationOnPositionChange; + bool mapLoaded; + bool initialStateOfupdateMapLocationOnPositionChange; - double? _direction; + double _direction; - StreamSubscription? _onLocationChangedStreamSubscription; - StreamSubscription? _compassStreamSubscription; - StreamSubscription? _locationStatusChangeSubscription; + StreamSubscription _onLocationChangedStreamSubscription; + StreamSubscription _compassStreamSubscription; + StreamSubscription _locationStatusChangeSubscription; @override void initState() { super.initState(); - WidgetsBinding.instance!.addObserver(this); + WidgetsBinding.instance.addObserver(this); initialStateOfupdateMapLocationOnPositionChange = widget.options.updateMapLocationOnPositionChange; @@ -55,7 +56,7 @@ class _MapsPluginLayerState extends State @override void dispose() { - WidgetsBinding.instance!.removeObserver(this); + WidgetsBinding.instance.removeObserver(this); _locationStatusChangeSubscription?.cancel(); _onLocationChangedStreamSubscription?.cancel(); _compassStreamSubscription?.cancel(); @@ -139,11 +140,11 @@ class _MapsPluginLayerState extends State if (onValue.latitude == null || onValue.longitude == null) { _currentLocation = LatLng(0, 0); } else { - _currentLocation = LatLng(onValue.latitude!, onValue.longitude!); + _currentLocation = LatLng(onValue.latitude, onValue.longitude); } - var height = 20.0 * (1 - (onValue.accuracy! / 100)); - var width = 20.0 * (1 - (onValue.accuracy! / 100)); + var height = 20.0 * (1 - (onValue.accuracy / 100)); + var width = 20.0 * (1 - (onValue.accuracy / 100)); if (height < 0 || width < 0) { height = 20; width = 20; @@ -159,7 +160,7 @@ class _MapsPluginLayerState extends State height: 20.0, width: 20.0, point: - LatLng(_currentLocation!.latitude, _currentLocation!.longitude), + LatLng(_currentLocation.latitude, _currentLocation.longitude), builder: (context) { return Stack( alignment: AlignmentDirectional.center, @@ -167,7 +168,7 @@ class _MapsPluginLayerState extends State if (_direction != null && widget.options.showHeading) ClipOval( child: Transform.rotate( - angle: _direction! / 180 * math.pi, + angle: _direction / 180 * math.pi, child: CustomPaint( size: Size(60.0, 60.0), painter: MyDirectionPainter(), @@ -184,7 +185,7 @@ class _MapsPluginLayerState extends State width: 20, decoration: BoxDecoration( shape: BoxShape.circle, - color: Colors.blue[300]!.withOpacity(0.7), + color: Colors.blue[300].withOpacity(0.7), ), ), ), @@ -225,7 +226,7 @@ class _MapsPluginLayerState extends State setState(() { mapLoaded = true; }); - animatedMapMove(_currentLocation!, widget.options.defaultZoom, + animatedMapMove(_currentLocation, widget.options.defaultZoom, widget.options.mapController, this); } }); @@ -233,14 +234,12 @@ class _MapsPluginLayerState extends State } } - void _moveMapToCurrentLocation({double? zoom}) { + void _moveMapToCurrentLocation({double zoom}) { if (_currentLocation != null) { animatedMapMove( - LatLng( - _currentLocation!.latitude, - _currentLocation!.longitude, - ), - zoom ?? widget.map.zoom, + LatLng(_currentLocation.latitude ?? LatLng(0, 0), + _currentLocation.longitude ?? LatLng(0, 0)), + zoom ?? widget.map.zoom ?? 15, widget.options.mapController, this, ); @@ -249,7 +248,7 @@ class _MapsPluginLayerState extends State void _handleLocationStatusChanges() { printLog(_stream.toString()); - bool? _locationStatusChanged; + bool _locationStatusChanged; if (_locationStatusChanged == null) { _locationStatusChangeSubscription = _stream.receiveBroadcastStream().listen((onData) { @@ -268,7 +267,7 @@ class _MapsPluginLayerState extends State void _handleCompassDirection() { if (widget.options.showHeading) { - _compassStreamSubscription = FlutterCompass.events!.listen((event) { + _compassStreamSubscription = FlutterCompass.events.listen((event) { setState(() { _direction = event.heading; }); @@ -281,8 +280,8 @@ class _MapsPluginLayerState extends State if (widget.options.onLocationUpdate == null) { printLog("Stream not provided"); } else { - widget.options.onLocationUpdate!( - LatLng(onValue.latitude!, onValue.longitude!), + widget.options.onLocationUpdate( + LatLng(onValue.latitude, onValue.longitude), onValue.speed, ); } @@ -314,7 +313,7 @@ class _MapsPluginLayerState extends State initialize(); _moveMapToCurrentLocation(zoom: widget.options.defaultZoom); if (widget.options.onTapFAB != null) { - widget.options.onTapFAB!(); + widget.options.onTapFAB(); } }, child: widget.options.moveToCurrentLocationFloatingActionButton ?? @@ -382,11 +381,11 @@ class _MapsPluginLayerState extends State } void forceMapUpdate() { - var zoom = widget.options.mapController!.zoom; - widget.options.mapController!.move(widget.options.mapController!.center, - widget.options.mapController!.zoom + 0.000001); - widget.options.mapController! - .move(widget.options.mapController!.center, zoom); + var zoom = widget.options.mapController.zoom; + widget.options.mapController.move(widget.options.mapController.center, + widget.options.mapController.zoom + 0.000001); + widget.options.mapController + .move(widget.options.mapController.center, zoom); } } diff --git a/lib/src/user_location_marker.dart b/lib/src/user_location_marker.dart index 1352ea6..6f72cc5 100644 --- a/lib/src/user_location_marker.dart +++ b/lib/src/user_location_marker.dart @@ -2,11 +2,11 @@ import 'package:flutter_map/flutter_map.dart'; class UserLocationMarker extends Marker { UserLocationMarker({ - required point, - required builder, - required width, - required height, - AnchorPos? anchorPos, + point, + builder, + width, + height, + AnchorPos anchorPos, }) : super( point: point, builder: builder, diff --git a/lib/src/user_location_options.dart b/lib/src/user_location_options.dart index ddd4375..76e8fe3 100755 --- a/lib/src/user_location_options.dart +++ b/lib/src/user_location_options.dart @@ -1,20 +1,20 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong2/latlong.dart'; +import 'package:latlong/latlong.dart'; class UserLocationOptions extends LayerOptions { BuildContext context; - List markers; - MapController? mapController; + List markers; + MapController mapController; - Widget? markerWidget; + Widget markerWidget; bool updateMapLocationOnPositionChange; bool showMoveToCurrentLocationFloatingActionButton; bool zoomToCurrentLocationOnLoad; - Widget? moveToCurrentLocationFloatingActionButton; + Widget moveToCurrentLocationFloatingActionButton; - void Function(LatLng location, double? speed)? onLocationUpdate; - Function()? onTapFAB; + void Function(LatLng location, double speed) onLocationUpdate; + Function() onTapFAB; double fabBottom; double fabRight; @@ -37,8 +37,8 @@ class UserLocationOptions extends LayerOptions { int locationUpdateIntervalMs; UserLocationOptions( - {required this.context, - required this.markers, + {@required this.context, + @required this.markers, this.mapController, this.markerWidget, this.onLocationUpdate, diff --git a/pubspec.yaml b/pubspec.yaml index 4f90b86..4913744 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,13 +5,13 @@ author: Gaurab Panthee homepage: https://github.com/igaurab/UserLocationPlugin environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.3.0 <3.0.0" dependencies: flutter: sdk: flutter location: ^4.1.1 - flutter_map: ^0.13.0 + flutter_map: ^0.12.0 flutter_compass: ^0.6.0 dev_dependencies: