Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The argument type 'LatLng' can't be assigned to the parameter type 'LatLng?'

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,
        ),
      ],
    );
  }

  }

screen shot of the error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Their website recomendation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading