NeshanMap class
A cross-platform widget that displays a Neshan map.
Supports iOS, Android, and Web:
- Mobile: renders the map inside a
WebView. - Web: renders the map inside an
<iframe>.
Key Parameters
| Parameter | Purpose |
|---|---|
| mapKey | Neshan API key (required) |
| config | Viewport & style settings (NeshanMapConfig) |
| markers | Initial set of NeshanMarkers to show on the map |
| controller | NeshanMapController for programmatic control |
| onLocationChanged | Called when the map centre changes |
| onMarkerTapped | Called when a marker is tapped |
| onError | Called on general errors |
| onLocationError | Called on location-permission / service errors |
Basic Usage
import 'package:neshan_maps_flutter/map.dart';
import 'package:latlong2/latlong.dart';
NeshanMap(
mapKey: 'your-neshan-api-key',
config: NeshanMapConfig(
initialCenter: LatLng(35.6892, 51.3890),
initialZoom: 15.0,
),
onLocationChanged: (lat, lng) {
debugPrint('Centre: $lat, $lng');
},
)
With Markers
Markers are passed directly to the widget, not via NeshanMapConfig. To add or remove markers after the map has loaded use NeshanMapController:
import 'package:flutter/material.dart';
import 'package:neshan_maps_flutter/map.dart';
import 'package:latlong2/latlong.dart';
final controller = NeshanMapController();
NeshanMap(
mapKey: 'your-neshan-api-key',
controller: controller,
markers: [
NeshanMarker(
id: 'hq',
position: LatLng(35.6892, 51.3890),
title: 'HQ',
color: Colors.red,
),
],
)
// Programmatically add another marker later:
await controller.ready;
controller.addMarker(
NeshanMarker(id: 'branch', position: LatLng(35.70, 51.40)),
);
Platform Notes
- On mobile, the map is rendered in a WebView, which requires internet connectivity to load the Neshan SDK.
- On web, the map is rendered in an iframe, which may have different security restrictions depending on the browser.
- The NeshanMapController.ready future should be awaited before calling controller methods to ensure the map is fully loaded.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- NeshanMap
Constructors
-
NeshanMap({Key? key, required String mapKey, NeshanMapConfig? config, List<
NeshanMarker> markers = const [], NeshanMapController? controller, void onLocationChanged(double lat, double lng)?, void onMarkerTapped(String markerId)?, NeshanErrorCallback? onError, NeshanErrorCallback? onLocationError, bool enableDebug = false}) -
Creates a Neshan map widget.
const
Properties
- config → NeshanMapConfig?
-
Viewport and style configuration for the map.
final
- controller → NeshanMapController?
-
Optional controller for programmatic map control.
final
- enableDebug → bool
-
Enables verbose debug logging to the console.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- mapKey → String
-
The Neshan API key required to display the map.
final
-
markers
→ List<
NeshanMarker> -
Initial list of markers to display on the map.
final
- onError → NeshanErrorCallback?
-
Called when a general error occurs (WebView error, iframe error, JSON
parse failure, etc.).
final
- onLocationChanged → void Function(double lat, double lng)?
-
Called whenever the map centre changes (pan or programmatic move).
final
- onLocationError → NeshanErrorCallback?
-
Called when a location-related error occurs.
final
- onMarkerTapped → void Function(String markerId)?
-
Called when a marker on the map is tapped.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< NeshanMap> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited