when am using fluuter_maps in MapOptions-> Center when entering the lat and lng am getting an error The argument type ‘LatLng’ can’t be assigned to the parameter type ‘LatLng?’.
class MapsView extends HookConsumerWidget {
MapsView({Key? key}) : super(key: key);
final MapController _mapController=MapController();
@override
Widget build(BuildContext context, WidgetRef ref) {
return FlutterMap(
options: MapOptions(
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
),
layers: [
TileLayerOptions(
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
userAgentPackageName: 'com.example.app',
),
],
nonRotatedChildren: [
AttributionWidget.defaultWidget(
source: 'OpenStreetMap contributors',
onSourceTapped: null,
),
],
);
}
}
>Solution :
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
class MapsView extends HookConsumerWidget {
MapsView({Key? key}) : super(key: key);
final MapController _mapController=MapController();
@override
Widget build(BuildContext context, WidgetRef ref) {
return FlutterMap(
options: MapOptions(
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
),
layers: [
TileLayerOptions(
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
userAgentPackageName: 'com.example.app',
),
],
nonRotatedChildren: [
AttributionWidget.defaultWidget(
source: 'OpenStreetMap contributors',
onSourceTapped: null,
),
],
);
}
}
import ‘package:latlong2/latlong.dart
that is not exported in the package so you have to import this manually to be able to assign values in it
