Supplemental information
Find below essential supplemental information such as covering unit testing, thread safety, and dependency management.
Unit testing
It's easy to write unit tests for your app logic that uses the HERE SDK as all classes are fully mockable. Below you can see an example using Mockito. This will also work with most other frameworks that allow to create mocked objects:
@GenerateMocks([Angle])
void main() {
group('Angle', () {
test('test Angle', () {
var mockAngle = MockAngle();
when(mockAngle.degrees).thenReturn(10.0);
expect(mockAngle.degrees, 10.0);
verify(mockAngle.degrees).called(1);
});
});
}Note that above we add the Mockito annotation @GenerateMocks([Angle]) to create a mock of the HERE SDK class Angle. In order to access the automatically created mock named MockAngle you need to import the created file, for example: import 'main_test.mocks.dart'.
It is not necessary to initialize the HERE SDK when writing unit tests.
For more information on unit testing for Flutter in general, refer to this introduction.
Check the "unit_testing_app" example to find more use case examples.
Track HERE SDK Usage Statistics
The HERE SDK provides a way to monitor network usage using UsageStats. This class collects statistics on uploaded and downloaded data. Use sdkNativeEngine.getSdkUsageStats() and sdkNativeEngine.enableUsageStats() to retrieve network statistics. To reset the counters, use sdkNativeEngine.clearPersistentUsageStats() and sdkNativeEngine.clearUsageStatsCache(). To enable tracking, use the following:
SDKNativeEngine.sharedInstance!.enableUsageStats(true);Once enabled, the HERE SDK tracks network usage across different modules. To retrieve and log the tracked data, use the following method:
void logUsageStats() {
List<UsageStats> currentUsageStats = SDKNativeEngine.sharedInstance!.sdkUsageStats;
for (var usageStat in currentUsageStats) {
print("UsageStats: Network Usage for feature: ${usageStat.feature.name}");
for (var currentNetworkUsage in usageStat.networkStats) {
print("UsageStats: Bytes sent: ${currentNetworkUsage.sentBytes}");
print("UsageStats: Bytes received: ${currentNetworkUsage.receivedBytes}");
print("UsageStats: Network requests sent: ${currentNetworkUsage.requestCounter}");
print("UsageStats: For method: ${currentNetworkUsage.methodCall}");
}
}
}Example logs may look like below. The log shows that the RENDERING layer was counted which occurs when data for the corresponding layer is requested by the application:
Network Usage for feature: rendering
Bytes sent: 12843
Bytes received: 257590
Network requests sent: 10
For method MapContent%RENDERINGUsageStats contains a list of NetworkStats for each Feature, such as RENDERING or SEARCH. Each NetworkStats entry includes sentBytes, receivedBytes, requestCounter, and the corresponding methodCall used by the respective Feature. UsageStats is retained only for the current app session.
Note that calling enableUsageStats() is not persisted by the HERE SDK - same as for other settings: therefore, UsageStats should be enabled every time before the initialization of the HERE SDK - if they have been enabled before at runtime and if you want to continue to track the network statistics. Also, please note that the gathered data is only counting HERE SDK usages for the executed app on a device.
Thread safety
The HERE SDK is not guaranteed to be thread safe and it is required to make calls to the SDK from the main thread. Internally, the HERE SDK will offload most of its work to a background thread, but callbacks to your code will always occur on the main thread. In general, thread safety is the responsibility of the caller.
Dependency management
Currently, dependency management, for example, via https://pub.dev/, is not yet supported. This means that the HERE SDK plugin must be copied locally to an application project as described in the Get started section.
Use the HERE SDK with other frameworks
You can use the HERE SDK with other frameworks. For example, it is possible to combine an open street map with a SearchEngine, if you wish to do so.
-
Xamarin: The HERE SDK does not support Xamarin, but customers can implement a wrapper for Xamarin on top of the public APIs offered by the HERE SDK. We do no commit to make changes to the HERE SDK to support the related test tooling for Xamarin.
-
React Native: React Native is not supported. However, customers can implement a wrapper on their own, but we do not provide any support for such a task.
Updated yesterday