Skip to main content

General principles

Deferred results

Some SDK methods (e.g., those that access a remote server) return deferred results as Future or CancelableOperation, in cases where it may be important to cancel the request. To work with them, create a data obtaining handler and an error handler.

Example of obtaining an object from the directory:

import 'package:dgis_mobile_sdk/dgis.dart' as sdk;

// Create an object for directory search
searchManager = sdk.SearchManager.createOnlineManager(context);

// Get the directory object by its identifier
final objects = await searchManager.searchByDirectoryObjectIds([objectId]).value;
final object = objects.isEmpty ? null : objects.first;

For more information on working with the object directory, see the Directory section.

Data channels

Some SDK objects provide data channels that can be processed. To subscribe to a data channel, specify a handler function. You can unsubscribe from a channel when data processing is no longer required. To work with the data channels, use the Channel interface.

Subscribing to Channel returns StreamSubscription.

Example of subscribing to change of the visible map area (channel of new rectangular areas):

import 'dart:async';

import 'package:dgis_mobile_sdk/dgis.dart' as sdk;

class SampleState extends State<Widget> {
late final sdk.Context sdkContext;
late final sdk.MapWidgetController mapWidgetController;
StreamSubscription<sdk.GeoRect>? visibleRectSubscription;

@override
void initState() {
super.initState();
sdkContext = sdk.DGis.initialize();
mapWidgetController = sdk.MapWidgetController(sdkContext);
_subscribeToVisibleRect();
}

Future<void> _subscribeToVisibleRect() async {
final map = await mapWidgetController.mapAsync;
visibleRectSubscription = map.camera.visibleRectChannel.listen((geoRect) {
debugPrint("Current rect: ${geoRect}");
});
}

@override
void dispose() {
visibleRectSubscription?.cancel();
super.dispose();
}
...
}